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

new Strategy raises an error from Typescript transpiler when used in passport.use() #189

Closed
2 tasks done
Tenshock opened this issue Sep 13, 2019 · 2 comments
Closed
2 tasks done

Comments

@Tenshock
Copy link

Tenshock commented Sep 13, 2019

Describe the bug
When I instanciate a new Strategy object in Typescript and I use this object in passport.use(), it raises an error from the typescript transpiler on the new Strategy line as follows:

Argument of type 'Strategy<unknown, Client>' is not assignable to parameter of type 'Strategy'.
  Property 'authenticate' is missing in type 'Strategy<unknown, Client>' but required in type 'Strategy'.

To Reproduce
Issuer and Client configuration:

import { AuthorizationParameters, Client, ClientMetadata, Issuer, Strategy, TokenSet } from 'openid-client'
import passport from 'passport'

class OidcRepositoryImpl {
    private static authorizationParameters: AuthorizationParameters
    private static client: Client
    private static openIDIssuer: Issuer<Client>

    private constructor(strategyName: string) {
        passport.use(
            strategyName,
            new Strategy({ client: OidcRepositoryImpl.client, params: OidcRepositoryImpl.authorizationParameters }, this.verify)
        )

        passport.serializeUser((user, done) => {
            done(null, user)
        })
        passport.deserializeUser((user, done) => {
            done(null, user)
        })
    }

    static async build(
        authorizationParameters: AuthorizationParameters,
        clientMetadata: ClientMetadata,
        issuerRealmUrl: string,
        strategyName: string
    ): Promise<OidcRepositoryImpl> {
        this.openIDIssuer = await Issuer.discover(issuerRealmUrl)
        this.client = new OidcRepositoryImpl.openIDIssuer.Client(clientMetadata)
        this.authorizationParameters = authorizationParameters

        return new OidcRepositoryImpl(strategyName)
    }
}

Steps to reproduce the behaviour:

  1. Write this code
  2. Try to build it with a transpiler, I use tsc
  3. See the same error

Expected behaviour
I don't know what it should do but I was using the exact same code in [email protected] and since I updated the package to 3.7.1 I have this error. When I override the typescript definition of the openid-client Strategy with an authenticate attribute, it works as expected. I don't know if it is really a bug or if I misunderstood something.

I think it's not relevant to show the code that calls this class to instanciate the Strategy and the parameters, as the bug is not related to a particular behaviour after it is executed, as it does not compile.

Environment:

  • openid-client version: v3.7.1
  • node version: v12.2.0

Additional context

  • i have searched the issues tracker on github for similar issues and couldn't find anything related.
  • the bug is happening on latest openid-client too.
@Tenshock Tenshock changed the title new Strategy raises errors from Typescript transpiler when used in passport.use() new Strategy raises an error from Typescript transpiler when used in passport.use() Sep 13, 2019
@panva panva closed this as completed in c0d59c4 Sep 13, 2019
@panva
Copy link
Owner

panva commented Sep 13, 2019

@Tenshock thank you for bringing this up. Apparently we missed this when bundling the types with 3.7.0. I just released 3.7.2 which fixes the issue 🤞

@Tenshock
Copy link
Author

I'm always impressed by your quick answer and patches, thank you a lot.

@github-actions github-actions bot locked and limited conversation to collaborators Apr 4, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants