swagger-ui
swagger-ui copied to clipboard
fix(oauth2): handle redirect params properly
Given the following URL after user logged in using casdoor, the UI app can not validate (checking the state param) the response bc an error parsing the params
redirect with hash
---
http://.../static/oauth2-redirect.html#token=eyJhbGci....?state=TW9....Sk=&token_type=bearer
before:
if (/code|token|error/.test(window.location.hash)) {
qp = window.location.hash.substring(1);
} else {
qp = location.search.substring(1);
}
after:
if (/code|token|error/.test(window.location.hash)) {
qp = window.location.hash.substring(1).replace('?', '&');
} else {
qp = location.search.substring(1);
}
btw, the default behavior on oauth2 would try to get the value for access_token
property from the oauth response if you are using a different name for the TOKEN property, it should be specified under components/securitySchemas/<key>/x-tokenName
components: {
securitySchemes: {
casdoor: {
type: 'oauth2',
'x-tokenName': 'awesomeTokenName',
flows: {
implicit: {
authorizationUrl: `http://blablabla/login/oauth/authorize`,
scopes: {},
},
},
},
},
}
related #6421
@fernandolguevara Thanks for the PR! I assume this change also needs to be propagated to /dist/oauth2-redirect.html
as well?
@tim-lai done 🙃
@fernandolguevara PR merged! Thanks for the fix and contribution!
@tim-lai can we have a new release with this fix ?
can we have a new release with this fix ?
Yup! I'll get a release out today, thanks.