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

TokenCache typing problem #170

Closed
bzums opened this issue Jan 19, 2018 · 4 comments
Closed

TokenCache typing problem #170

bzums opened this issue Jan 19, 2018 · 4 comments
Assignees
Labels

Comments

@bzums
Copy link
Collaborator

bzums commented Jan 19, 2018

If initialising the TokenCache like:

const oAuthConfig = {
  credentialsDir,
  accessTokenEndpoint,
  tokenInfoEndpoint,
  grantType: OAuthGrantType.CLIENT_CREDENTIALS_GRANT
};

const cache = new TokenCache(tokenConfig, oAuthConfig);

we currently get the following error:

> src/services/token-cache.ts(29,38): error TS2345: Argument of type '{ credentialsDir: string; accessTokenEndpoint: string; tokenInfoEndpoint: string; grantType: OAuthGrantType; }' is not assignable to parameter of type 'TokenCacheOAuthConfig'.
>   Type '{ credentialsDir: string; accessTokenEndpoint: string; tokenInfoEndpoint: string; grantType: OAuthGrantType; }' is not assignable to type 'CredentialsClientConfig & GrantConfigBase & { grantType: OAuthGrantType.REFRESH_TOKEN_GRANT; refreshToken: string; } & { tokenInfoEndpoint: string; }'.
>     Type '{ credentialsDir: string; accessTokenEndpoint: string; tokenInfoEndpoint: string; grantType: OAuthGrantType; }' is not assignable to type 'CredentialsClientConfig'.
>       Property 'clientId' is missing in type '{ credentialsDir: string; accessTokenEndpoint: string; tokenInfoEndpoint: string; grantType: OAuthGrantType; }'.

which can be fixed via an explicitly typing:

const oAuthConfig: TokenCacheOAuthConfig = { ... };

However, that should not be necessary for the user. We have to investigate further why this problem occurs.

@bzums bzums added the 2.0.0 label Jan 19, 2018
@bzums bzums self-assigned this Jan 19, 2018
@ISO50
Copy link
Collaborator

ISO50 commented Jan 22, 2018

@bzums

When using the above method Typescript infers OAuthGrantType instead of OAuthGrantType.CLIENT_CREDENTIALS_GRANT for the grantType field.

This can be fixed by:

  1. oAuthConfig: TokenCacheOAuthConfig
  2. inlining:
const cache = new TokenCache(tokenConfig, {
  credentialsDir: 'credentialsDir',
  accessTokenEndpoint: 'accessTokenEndpoint',
  tokenInfoEndpoint: 'tokenInfoEndpoint',
  grantType: OAuthGrantType.CLIENT_CREDENTIALS_GRANT
});
  1. Or using Type assertions:
const oAuthConfig = {
  credentialsDir: 'credentialsDir',
  accessTokenEndpoint: 'accessTokenEndpoint',
  tokenInfoEndpoint: 'tokenInfoEndpoint',
  grantType: OAuthGrantType.CLIENT_CREDENTIALS_GRANT as OAuthGrantType.CLIENT_CREDENTIALS_GRANT,
};

Maybe using String Literals instead of Enums could make that work without this workarounds.

@ISO50
Copy link
Collaborator

ISO50 commented Jan 23, 2018

One of the underlying problems, read here: microsoft/TypeScript#9489

ISO50 added a commit that referenced this issue Jan 24, 2018
@ISO50
Copy link
Collaborator

ISO50 commented Jan 24, 2018

@ISO50
Copy link
Collaborator

ISO50 commented Jan 25, 2018

Fixed by #171

@ISO50 ISO50 closed this as completed Jan 25, 2018
ISO50 added a commit that referenced this issue Jan 30, 2018
ISO50 added a commit that referenced this issue Jan 30, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants