node-oauth2-server icon indicating copy to clipboard operation
node-oauth2-server copied to clipboard

`saveToken` has incorrect type signature

Open papermana opened this issue 3 months ago • 0 comments

Specify your setup

  • Operating System: macOS 15.6.1
  • Node version: 22.17.0
  • npm version: -
  • version of @node-oauth/oauth2-server: 5.2.1
  • which OAuth2 workflow: Authorization Code
  • at which workflow step does the error occur: step D

Describe the bug

On interface BaseModel, function saveToken is typed as having Token as a parameter (here) and returning Token. In turn, the Token interface is typed as having client and user defined (here). So according to the typings, it would be enough to define this:

saveToken(token, _client, _user) {
  return token;
}

However, at least in the Authorization Code flow, client and user are not present on the input but are required for the output (here and here).

To Reproduce

Create a model with:

saveToken(token) {
  // some side effect
  return token;
}

Then, call oauth.token(oauthRequest, oauthResponse) with valid parameters.

Expected behavior

The saveToken function should have as first parameter Omit<Token, 'client' | 'user'>. Alternatively, it should be passed those properties in the token object.

Screenshots

Additional context

papermana avatar Sep 02 '25 13:09 papermana