diff --git a/.changesets/a6vql.minor.md b/.changesets/a6vql.minor.md new file mode 100644 index 00000000..b861ca81 --- /dev/null +++ b/.changesets/a6vql.minor.md @@ -0,0 +1 @@ +Feat: Add `idToken` to the return value of LinkedIn's `validateAuthorizationCode(code: string)` \ No newline at end of file diff --git a/.changesets/dj9ch.patch.md b/.changesets/dj9ch.patch.md new file mode 100644 index 00000000..57779adf --- /dev/null +++ b/.changesets/dj9ch.patch.md @@ -0,0 +1 @@ +Fix: Make `refreshToken` optional for the return value of LinkedIn's `validateAuthorizationCode(code: string)` \ No newline at end of file diff --git a/src/providers/linkedin.ts b/src/providers/linkedin.ts index 0731b482..dba783df 100644 --- a/src/providers/linkedin.ts +++ b/src/providers/linkedin.ts @@ -31,25 +31,31 @@ export class LinkedIn implements OAuth2Provider { } public async validateAuthorizationCode(code: string): Promise { - const result = await this.client.validateAuthorizationCode(code, { - authenticateWith: "request_body", - credentials: this.clientSecret - }); + const result = await this.client.validateAuthorizationCode( + code, + { + authenticateWith: "request_body", + credentials: this.clientSecret + } + ); const tokens: LinkedInTokens = { + idToken: result.id_token, accessToken: result.access_token, accessTokenExpiresAt: createDate(new TimeSpan(result.expires_in, "s")), - refreshToken: result.refresh_token, - refreshTokenExpiresAt: createDate(new TimeSpan(result.refresh_token_expires_in, "s")) + refreshToken: result.refresh_token ?? null, + refreshTokenExpiresAt: result.refresh_token_expires_in + ? createDate(new TimeSpan(result.refresh_token_expires_in, "s")) + : null }; return tokens; } - public async refreshAccessToken(accessToken: string): Promise { - const result = await this.client.refreshAccessToken(accessToken, { + public async refreshAccessToken(accessToken: string): Promise { + const result = await this.client.refreshAccessToken(accessToken, { authenticateWith: "request_body", credentials: this.clientSecret }); - const tokens: LinkedInTokens = { + const tokens: LinkedInRefreshedTokens = { accessToken: result.access_token, accessTokenExpiresAt: createDate(new TimeSpan(result.expires_in, "s")), refreshToken: result.refresh_token, @@ -59,7 +65,15 @@ export class LinkedIn implements OAuth2Provider { } } -interface TokenResponseBody { +interface AuthorizationCodeResponseBody { + id_token: string; + access_token: string; + expires_in: number; + refresh_token?: string; // available only if your application is authorized for programmatic refresh tokens + refresh_token_expires_in?: number; +} + +interface RefreshTokenResponseBody { access_token: string; expires_in: number; refresh_token: string; @@ -67,6 +81,14 @@ interface TokenResponseBody { } export interface LinkedInTokens { + idToken: string; + accessToken: string; + accessTokenExpiresAt: Date; + refreshToken: string | null; + refreshTokenExpiresAt: Date | null; +} + +export interface LinkedInRefreshedTokens { accessToken: string; accessTokenExpiresAt: Date; refreshToken: string;