Skip to content

Commit

Permalink
misc: add password grant warning and sync 4.x (#217)
Browse files Browse the repository at this point in the history
* misc: add password grant deprecated warning

* feat: expose userAgent

* Add docs on use of cachePrefix

based on findings in this issue: #214

---------

Co-authored-by: Elridge D'Mello <[email protected]>
  • Loading branch information
embbnux and Elridge D'Mello authored Jun 16, 2023
1 parent 6ef51bb commit 9632bca
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
35 changes: 35 additions & 0 deletions sdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,41 @@ rcsdk
});
```
### Multi User Login
If you need to have multiple users login in to different instances of the sdk, you can use the `cachePrefix` SDK option. Specify different `cachePrefix` values for each instance.
```js
const rcsdk1 = new RingCentral.SDK({
server: RingCentral.SDK.server.sandbox,
clientId: 'yourClientId',
clientSecret: 'yourClientSecret',
cachePrefix: 'user1',
});
rcsdk1.login({
username: '18001234567',
extension: '101',
password: 'password1'
})
const rcsdk2 = new RingCentral.SDK({
server: RingCentral.SDK.server.sandbox,
clientId: 'yourClientId',
clientSecret: 'yourClientSecret',
cachePrefix: 'user2',
});
rcsdk1.login({
username: '18005557777',
extension: '102',
password: 'password2'
})
```
This prevents login state from being shared between the two instances `rcsdk1` and `rcsdk2`
## Handling login success
Because the login process is asynchronous, you need to call the promise's `then` method and pass your success handler as
Expand Down
1 change: 1 addition & 0 deletions sdk/src/platform/Platform-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ describe('RingCentral.platform.Platform', () => {
});
await platform.get(path, null);
expect(request.headers.get('x-user-agent')).to.equal(`RCJSSDK/${version}`);
expect(platform.userAgent).to.equal(`RCJSSDK/${version}`);
}),
);

Expand Down
8 changes: 8 additions & 0 deletions sdk/src/platform/Platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,10 @@ export default class Platform extends EventEmitter {
body.username = username;
}
body.password = password;
// eslint-disable-next-line no-console
console.warn(
'Username/password authentication is deprecated. Please migrate to the JWT grant type.',
);
} else if (jwt) {
body.grant_type = 'urn:ietf:params:oauth:grant-type:jwt-bearer';
body.assertion = jwt;
Expand Down Expand Up @@ -841,6 +845,10 @@ export default class Platform extends EventEmitter {
public get codeVerifier() {
return this._codeVerifier;
}

public get userAgent() {
return this._userAgent;
}
}

export interface PlatformOptions extends AuthOptions {
Expand Down

0 comments on commit 9632bca

Please sign in to comment.