node-openid-client icon indicating copy to clipboard operation
node-openid-client copied to clipboard

Typescript Support?

Open hronro opened this issue 8 years ago • 17 comments

Is there any plans to support Typescript?

hronro avatar Jun 03 '18 07:06 hronro

I don’t intend to provide any myself.

panva avatar Jun 03 '18 08:06 panva

Change of heart, i'll bundle definitions with 3.x

panva avatar Mar 06 '19 08:03 panva

@panva: Just so that we can get an idea, when do you plan to release v3? Thx

mdestagnol avatar Mar 09 '19 19:03 mdestagnol

@panva great news. do you need support or are you already about to migrate the whole project to Typescript?

jaulz avatar Mar 25 '19 14:03 jaulz

@jaulz i'm not gonna migrate the project, i'll expose types only. Same note applies as in https://github.com/panva/jose/issues/9 if you could review the types there and how they're defined, I'm not a TS user myself so feedback on the types themselves would be great.

panva avatar Mar 25 '19 15:03 panva

@panva great. I just had a superficial look at the declarations and they look clean and exactly how it should be 😊 did you already start with the types? Otherwise I could raise a PR with my basic types and we could go on from there.

jaulz avatar Mar 25 '19 15:03 jaulz

If you could paste a gist here it'd be a good starting point. Thanks

panva avatar Mar 25 '19 15:03 panva

@panva sure, here you go. I'm not sure about the fields since I am not 100% familiar with the specification but it's basically what I took from this example: https://connect2id.com/products/server/docs/api/discovery

declare module "openid-client" {
    export class OpenIdConnectError extends Error {
      error: string;
      error_description?: string;
      error_uri?: string;
      state?: string;
      scope?: string;
      response?: any;
    }
  
    type DiscoverOptions = {
      issuer: string;
      authorization_endpoint: string;
      token_endpoint: string;
      userinfo_endpoint: string;
      jwks_uri: string;
    };
  
    export class Issuer {
      constructor(options: DiscoverOptions);
  
      static discover(url: string): Promise<Issuer>;
  
      Client: typeof Client;
  
      useRequest(): void;
    }
  
    type ClientOptions = {
      client_id: string;
      client_secret: string;
    };
  
    type ClientKeyStore = any;
  
    type ClientTokenSet = {
      claims: any;
    };
  
    type SupportedScopes =
      | "openid"
      | "profile"
      | "email"
      | "address"
      | "phone"
      | "offline_access";
  
    type ResponseTypesScopes =
      | "code"
      | "token"
      | "id_token"
      | "id_token token"
      | "code id_token"
      | "code id_token token";
  
    type ResponseModesScopes = "query" | "fragment" | "form_post";
  
    type GrantTypesSupported =
      | "implicit"
      | "authorization_code"
      | "refresh_token"
      | "password"
      | "client_credentials"
      | "urn:ietf:params:oauth:grant-type:jwt-bearer";
  
    type CodeChallengeMethodsSupported = "S256" | "plain";
  
    type TokenEndpointAuthMethodsSupported =
      | "client_secret_basic"
      | "client_secret_post"
      | "client_secret_jwt"
      | "private_key_jwt"
      | "self_signed_tls_client_auth"
      | "none";
  
    type TokenEndpointAuthSigningAlgValuesSupported =
      | "HS256"
      | "HS384"
      | "HS512"
      | "RS256"
      | "RS384"
      | "RS512"
      | "PS256"
      | "PS384"
      | "PS512"
      | "ES256"
      | "ES384"
      | "ES512";
  
    type RequestObjectSigningAlgValuesSupported =
      | "HS256"
      | "HS384"
      | "HS512"
      | "RS256"
      | "RS384"
      | "RS512"
      | "PS256"
      | "PS384"
      | "PS512"
      | "ES256"
      | "ES384"
      | "ES512"
      | "none";
  
    type SubjectTypesSupported = "public" | "pairwise";
  
    type IdTokenSigningAlgValuesSupported =
      | "RS256"
      | "RS384"
      | "RS512"
      | "PS256"
      | "PS384"
      | "PS512"
      | "ES256"
      | "ES384"
      | "ES512"
      | "HS256"
      | "HS384"
      | "HS512"
      | "none";
  
    type IdTokenEncryptionAlgValuesSupported =
      | "RSA1_5"
      | "RSA-OAEP"
      | "RSA-OAEP-256"
      | "ECDH-ES"
      | "ECDH-ES+A128KW"
      | "ECDH-ES+A192KW"
      | "ECDH-ES+A256KW"
      | "dir"
      | "A128KW"
      | "A192KW"
      | "A256KW"
      | "A128GCMKW"
      | "A192GCMKW"
      | "A256GCMKW";
  
    type IdTokenEncryptionEncValuesSupported =
      | "A128CBC-HS256"
      | "A192CBC-HS384"
      | "A256CBC-HS512"
      | "A128GCM"
      | "A192GCM"
      | "A256GCM";
  
    type UserinfoSigningAlgValuesSupported =
      | "RS256"
      | "RS384"
      | "RS512"
      | "PS256"
      | "PS384"
      | "PS512"
      | "ES256"
      | "ES384"
      | "ES512"
      | "HS256"
      | "HS384"
      | "HS512";
  
    type UserinfoEncryptionAlgValuesSupported =
      | "RSA1_5"
      | "RSA-OAEP"
      | "RSA-OAEP-256"
      | "ECDH-ES"
      | "ECDH-ES+A128KW"
      | "ECDH-ES+A192KW"
      | "ECDH-ES+A256KW"
      | "dir"
      | "A128KW"
      | "A192KW"
      | "A256KW"
      | "A128GCMKW"
      | "A192GCMKW"
      | "A256GCMKW";
  
    type UserinfoEncryptionEncValuesSupported =
      | "A128CBC-HS256"
      | "A192CBC-HS384"
      | "A256CBC-HS512"
      | "A128GCM"
      | "A192GCM"
      | "A256GCM";
  
    type DisplayValuesSupported = "page" | "popup";
  
    type ClaimTypesSupported = "normal";
  
    type ClaimsSupported =
      | "sub"
      | "iss"
      | "auth_time"
      | "acr"
      | "name"
      | "given_name"
      | "family_name"
      | "nickname"
      | "email"
      | "email_verified";
  
    type Metadata = {
      issuer: string;
      jwks_uri: string;
      authorization_endpoint: string;
      token_endpoint: string;
      registration_endpoint: string;
      introspection_endpoint: string;
      revocation_endpoint: string;
      userinfo_endpoint: string;
      scopes_supported: SupportedScopes[];
      response_types_supported: ResponseTypesScopes[];
      response_modes_supported: ResponseModesScopes[];
      grant_types_supported: GrantTypesSupported[];
      code_challenge_methods_supported: CodeChallengeMethodsSupported[];
      token_endpoint_auth_methods_supported: TokenEndpointAuthMethodsSupported[];
      token_endpoint_auth_signing_alg_values_supported: TokenEndpointAuthSigningAlgValuesSupported[];
      request_object_signing_alg_values_supported: RequestObjectSigningAlgValuesSupported[];
      ui_locales_supported: string[];
      request_parameter_supported: boolean;
      request_uri_parameter_supported: boolean;
      require_request_uri_registration: boolean;
      tls_client_certificate_bound_access_tokens: boolean;
      request_uri_quota: number;
      subject_types_supported: SubjectTypesSupported[];
      acr_values_supported: string[];
      id_token_signing_alg_values_supported: IdTokenSigningAlgValuesSupported[];
      id_token_encryption_alg_values_supported: IdTokenEncryptionAlgValuesSupported[];
      id_token_encryption_enc_values_supported: IdTokenEncryptionEncValuesSupported[];
      userinfo_signing_alg_values_supported: UserinfoSigningAlgValuesSupported[];
      userinfo_encryption_alg_values_supported: UserinfoEncryptionAlgValuesSupported[];
      userinfo_encryption_enc_values_supported: UserinfoEncryptionEncValuesSupported[];
      display_values_supported: DisplayValuesSupported[];
      claim_types_supported: ClaimTypesSupported[];
      claims_supported: ClaimsSupported[];
      claims_parameter_supported: boolean;
      frontchannel_logout_supported: boolean;
      frontchannel_logout_session_supported: boolean;
      backchannel_logout_supported: boolean;
      backchannel_logout_session_supported: boolean;
    };
  
    export class Client {
      constructor(options: ClientOptions, keystore?: ClientKeyStore);
  
      static fromUri(
        registrationClientUri: string,
        registrationAccessToken: string,
        keystore?: ClientKeyStore
      ): Promise<Client>;
  
      CLOCK_TOLERANCE: number;
  
      issuer: {
        metadata: Metadata;
      };
  
      authorizationUrl(params: {
        redirect_uri: string;
        scope: string;
        claims?: object;
        [key: string]: any;
      }): string;
  
      authorizationPost(params: {
        redirect_uri: string;
        scope: string;
        claims?: object;
        [key: string]: any;
      }): string;
  
      authorizationCallback(
        callbackUri: string,
        query: object,
        params: {
          state: string;
          response_type: string;
          nonce?: string;
          max_age?: number;
          code_verifier?: any;
        }
      ): Promise<ClientTokenSet>;
  
      callbackParams(): { code: string };
    }
  }

jaulz avatar Mar 27 '19 15:03 jaulz

@jaulz what would be error_uri for OpenIdConnectError.state?

wegylexy avatar Apr 02 '19 18:04 wegylexy

@wegylexy here you can see it: https://openid.net/specs/openid-client-initiated-backchannel-authentication-core-1_0-01.html#rfc.section.13

"OPTIONAL. A URI identifying a human-readable web page with information about the error, used to provide the client developer with additional information about the error. Values for the "error_uri" parameter MUST conform to the URI-reference syntax and thus MUST NOT include characters outside the set %x21 / %x23-5B / %x5D-7E."

jaulz avatar Apr 04 '19 18:04 jaulz

@jaulz so it should be string, or missing a type declaration

wegylexy avatar Apr 05 '19 04:04 wegylexy

@wegylexy oh yeah, sure. sorry for the mistake!

jaulz avatar Apr 05 '19 06:04 jaulz

Do we have a eta for the release of version 3, or could we bundle in the above type definition into version 2?

joshuaanthonydeleon avatar Apr 11 '19 05:04 joshuaanthonydeleon

@joshuaanthonydeleon hmm, the above is incomplete.

wegylexy avatar Apr 11 '19 06:04 wegylexy

@joshuaanthonydeleon

Do we have a eta for the release of version 3

Earliest with the release of node 12 end of april if all dependencies work out of the box, if not, once they get fixed.

panva avatar Apr 11 '19 07:04 panva

I started with the typings I needed and added them to DT.

See https://github.com/DefinitelyTyped/DefinitelyTyped/pull/35412

ulrichb avatar May 15 '19 09:05 ulrichb

I've opened a PR that adds a comprehensive set of definitions

https://github.com/panva/node-openid-client/pull/184

theogravity avatar Sep 05 '19 01:09 theogravity