Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AuthenticationService getPayload method should use payload of AuthenticationResult #3419

Open
claustres opened this issue Jan 31, 2024 · 1 comment

Comments

@claustres
Copy link
Contributor

claustres commented Jan 31, 2024

We have created our own authentication strategy in order to automatically renew JWT, details can be see here. However, it appears that if the original token does contain some additional payload, the additional fields are lost in the newly generated token.

It seems to be caused by getPayload() because even if the input authentication result contains the payload it is not taken into account when generating the new token.

May we suggest to do something like this:

async getPayload(_authResult: AuthenticationResult, params: AuthenticationParams) {
    // Uses `params.payload`, `_authResult.authentication.payload`  or returns an empty payload
    if (_authResult.authentication && _authResult.authentication.payload) return _authResult.authentication.payload
    const { payload = {} } = params
    
    return payload
  }
@claustres
Copy link
Contributor Author

claustres commented Jan 31, 2024

I've tested the approach by extending the AuthenticationService class, it appears to work but I needed to remove from the result payload ['aud', 'iss'] otherwise it conflicts with default token options in config I guess. Here is the error message: create: Bad "options.expiresIn" option the payload already has an "exp" property.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant