swagger-ui icon indicating copy to clipboard operation
swagger-ui copied to clipboard

fix(oauth2): handle redirect params properly

Open fernandolguevara opened this issue 2 years ago • 0 comments

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 avatar Aug 08 '22 11:08 fernandolguevara

@fernandolguevara Thanks for the PR! I assume this change also needs to be propagated to /dist/oauth2-redirect.html as well?

tim-lai avatar Aug 10 '22 16:08 tim-lai

@tim-lai done 🙃

fernandolguevara avatar Aug 10 '22 18:08 fernandolguevara

@fernandolguevara PR merged! Thanks for the fix and contribution!

tim-lai avatar Aug 12 '22 16:08 tim-lai

@tim-lai can we have a new release with this fix ?

fernandolguevara avatar Aug 16 '22 10:08 fernandolguevara

can we have a new release with this fix ?

Yup! I'll get a release out today, thanks.

tim-lai avatar Aug 17 '22 18:08 tim-lai