bsso
Version:
Bloomberg SSO js utilities
58 lines (42 loc) • 1.99 kB
Markdown
[][package-url]
[](https://app.travis-ci.com/github/jcgertig/bsso)
[](https://codeclimate.com/github/jcgertig/bsso)
[](https://codeclimate.com/github/jcgertig/bsso/coverage)
```
yarn add bsso
```
First setup [react-native-get-random-values](https://github.com/LinusU/react-native-get-random-values) and[react-native-url-polyfill](https://github.com/charpeni/react-native-url-polyfill) and
[](https://www.npmjs.com/package/text-encoding-polyfill).
```js
import { BSSO } from 'bsso';
const bsso = new BSSO({
clientId: 'se-mobile-app',
redirectUri: 'http://localhost:8080/'
});
const tokenFromRedirectUrl = new URLSearchParams(window.location.hash).get('#token');
if (tokenFromRedirectUrl) {
// if we have #token, we are ready for redirect
console.log('redirect');
window.location.replace(await bsso.getRedirectURL(tokenFromRedirectUrl));
} else {
const code = new URLSearchParams(window.location.search).get("code");
if (code) {
// if we have the code, we are ready to continue getting token for authorization
const activeToken = await bsso.getToken(code);
console.log('activeToken', activeToken);
}
}
```
-------------------------------
| Method | Arguments | Return |
|----------------|-------------------------------|---------|
| getToken | code?: string | string |
| isExpired | | boolean |
| getRedirectURL | token: string, scope?: string | string |
| toJSON | | object |
[]: https://npmjs.com/package/bsso