Generate Authorize URI.
yarn add @rc-ex/authorize-uri
import RingCentral from '@rc-ex/core';
import AuthorizeUriExtension from '@rc-ex/authorize-uri';
const rc = new RingCentral(...);
const authorizeUriExtension = new AuthorizeUriExtension();
await rc.installExtension(authorizeUriExtension);
const authorizeUri = authorizeUriExtension.buildUri({
state: 'hello',
redirect_uri: 'https://example.com',
});
For a working sample, please check this test case.
First and foremost, you should not specify client secret in your project, that's the whole point of PKCE.
Secondly, specify code_challenge_method: 'S256'
:
const authorizeUri = authorizeUriExtension.buildUri({
state: 'hello',
redirect_uri: 'https://example.com',
code_challenge_method: 'S256',
});
And you should save the codeVerifier
:
const codeVerifier = authorizeUriExtension.codeVerifier;
You may need to persist codeVerifier
in case browser web page refreshes.
And when you make the authorize API call, remember to specify code_verifier
:
await rc.authorize({
code: '...',
redirect_uri: '...',
code_verifier: codeVerifier,
});
Optionally, you can specify baseAuthorizationUri
as parameter to the constructor of this extension.
If it's not specified, ${rc.rest.server}/restapi/oauth/authorize
is used as baseAuthorizationUri
.