diff --git a/sdk/src/platform/Platform-spec.ts b/sdk/src/platform/Platform-spec.ts index d2bdef2..6a1861a 100644 --- a/sdk/src/platform/Platform-spec.ts +++ b/sdk/src/platform/Platform-spec.ts @@ -82,6 +82,42 @@ describe('RingCentral.platform.Platform', () => { }), ); + it( + 'login with JWT', + asyncTest(async sdk => { + const platform = sdk.platform(); + + await platform.auth().cancelAccessToken(); + + authentication(); + + await platform.login({ + jwt: 'foo', + }); + + expect((await platform.auth().data()).access_token).to.equal('ACCESS_TOKEN'); + }), + ); + + it( + 'login with username/password', + asyncTest(async sdk => { + const platform = sdk.platform(); + + await platform.auth().cancelAccessToken(); + + authentication(); + + await platform.login({ + username: 'foo', + password: 'foo', + extension: 'foo', + }); + + expect((await platform.auth().data()).access_token).to.equal('ACCESS_TOKEN'); + }), + ); + it( 'login with code from usePKCE flow without client secret', asyncTest( diff --git a/sdk/src/platform/Platform.ts b/sdk/src/platform/Platform.ts index e5a4863..e6e21ea 100644 --- a/sdk/src/platform/Platform.ts +++ b/sdk/src/platform/Platform.ts @@ -422,6 +422,7 @@ export default class Platform extends EventEmitter { password, extension = '', code, + jwt, access_token_ttl, refresh_token_ttl, access_token, @@ -452,7 +453,7 @@ export default class Platform extends EventEmitter { //TODO Potentially make a request to /oauth/tokeninfo json = {access_token, ...options}; } else { - if (!code) { + if (!code && !jwt) { body.grant_type = 'password'; if (extension && extension.length > 0) { body.username = `${username}*${extension}`; @@ -460,6 +461,9 @@ export default class Platform extends EventEmitter { body.username = username; } body.password = password; + } else if (jwt) { + body.grant_type = 'urn:ietf:params:oauth:grant-type:jwt-bearer'; + body.assertion = jwt; } else if (code) { //@see https://developers.ringcentral.com/legacy-api-reference/index.html#!#RefAuthorizationCodeFlow body.grant_type = 'authorization_code'; @@ -834,6 +838,7 @@ export interface LoginOptions { password?: string; extension?: string; code?: string; + jwt?: string; access_token?: string; access_token_ttl?: number; refresh_token_ttl?: number;