feathersjs / docs

[MOVED] Legacy Feathers documentation
https://crow.docs.feathersjs.com/
MIT License
242 stars 532 forks source link

fix(oauth): authentication payload expects 'accessToken' not 'access_token' #1549

Closed miguelrk closed 2 years ago

miguelrk commented 2 years ago

Despite the access token being passed into the url after successfull oauth flow in snake case ('access_token'), the payload of the authentication service expects the key to be passed in camel case ('accessToken'). The exact place where 'accessToken' is destructured/used can be seen bellow:

// from feathers/packages/authentication/src/jwt.ts

async authenticate (authentication: AuthenticationRequest, params: Params) {
    const { accessToken } = authentication; // <----- THIS LINE
    const { entity } = this.configuration;

    if (!accessToken) {
      throw new NotAuthenticated('No access token');
    }

    const payload = await this.authentication.verifyAccessToken(accessToken, params.jwt);
    const result = {
      accessToken,
      authentication: {
        strategy: 'jwt',
        accessToken,
        payload
      }
    };

    if (entity === null) {
      return result;
    }

    const entityId = await this.getEntityId(result, params);
    const value = await this.getEntity(entityId, params);

    return {
      ...result,
      [entity]: value
    };
  }

We could otherwise also allow both if this is desired with for example:

const accessToken = authentication.accessToken || authentication.access_token

It this would be better, let me know and I can do a quick update to the feathers-authentication package (jwt.ts) to allow for this.

Many thanks!

netlify[bot] commented 2 years ago

✔️ Deploy Preview for feathers-docs ready!

🔨 Explore the source changes: b91c49cbb29bf178b1fd7f2131f22d8ec1a94487

🔍 Inspect the deploy log: https://app.netlify.com/sites/feathers-docs/deploys/619cc36f1874b0000748008a

😎 Browse the preview: https://deploy-preview-1549--feathers-docs.netlify.app

daffl commented 2 years ago

Thank you!