1.0.2 • Published 3 years ago
auth_lib_team3_test v1.0.2
Test library for authentication and authorization
- Install:
npm i auth_lib_team3_test
- Auth:
import { FfAuth } from 'auth_lib_team3_test';
// Setup
const appAuth = new FfAuth({
clientId: '<clientId>',
authorizationUri: 'https:///authorize',
accessTokenUri: 'https:///token',
redirectUri: 'http://localhost:3000/callback',
logoutUri: 'https:///logout',
logoutRedirectUri: 'http://localhost:3000/logout',
scopes: ['openid']
});
appAuth.startAutomaticTokenRefresh().then(() => {
const account = '<myaccountid>';
const resourceType = 'Patient';
const project = '<myprojectId>';
// Sign adds access_token etc. to your request options
const request = await appAuth.sign({
method: 'GET',
url: `https://fhir.us.lifeomic.com/${account}/dstu3/${resourceType}?_tag=http%3A%2F%2Flifeomic.com%2Ffhir%2Fdataset%${project}&pageSize=5`
});
const response = await fetch(request.url, request);
console.log(response);
});
Token Storage
By default LOAuth
will store the token in local storage and hydrate any existing session from there. To overwrite the storage location you can pass a storage object in options along with a custom storage key.
import { FfAuth } from 'auth_lib_team3_test';
const appAuth = new FfAuth({
...oauthConfig,
storageKey: 'my-key',
storage: {
getItem(key: string) {
return sessionStorage.getItem(key);
},
setItem(key: string, value: string) {
return sessionStorage.setItem(key, value);
},
removeItem(key: string) {
return sessionStorage.removeItem(key)
}
}
});
// or
const appAuth = new FfAuth({
...oauthConfig,
storageKey: 'my-key',
storage: sessionStorage,
});