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

Typescript Support? #97

Closed
hronro opened this issue Jun 3, 2018 · 17 comments
Closed

Typescript Support? #97

hronro opened this issue Jun 3, 2018 · 17 comments

Comments

@hronro
Copy link

hronro commented Jun 3, 2018

Is there any plans to support Typescript?

@panva
Copy link
Owner

panva commented Jun 3, 2018

I don’t intend to provide any myself.

@panva panva closed this as completed Jun 3, 2018
@panva
Copy link
Owner

panva commented Mar 6, 2019

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

@mdestagnol
Copy link

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

@jaulz
Copy link
Contributor

jaulz commented Mar 25, 2019

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

@panva
Copy link
Owner

panva commented Mar 25, 2019

@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.

@jaulz
Copy link
Contributor

jaulz commented Mar 25, 2019

@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.

@panva
Copy link
Owner

panva commented Mar 25, 2019

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

@jaulz
Copy link
Contributor

jaulz commented Mar 27, 2019

@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 };
    }
  }

@wegylexy
Copy link

wegylexy commented Apr 2, 2019

@jaulz what would be error_uri for OpenIdConnectError.state?

@jaulz
Copy link
Contributor

jaulz commented Apr 4, 2019

@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."

@wegylexy
Copy link

wegylexy commented Apr 5, 2019

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

@jaulz
Copy link
Contributor

jaulz commented Apr 5, 2019

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

@joshuaanthonydeleon
Copy link

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

@wegylexy
Copy link

@joshuaanthonydeleon hmm, the above is incomplete.

@panva
Copy link
Owner

panva commented Apr 11, 2019

@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.

@ulrichb
Copy link

ulrichb commented May 15, 2019

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

See DefinitelyTyped/DefinitelyTyped#35412

@theogravity
Copy link
Contributor

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

#184

@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

8 participants