3.6.4 • Published 4 months ago

@lifeomic/app-tools v3.6.4

Weekly downloads
482
License
MIT
Repository
github
Last release
4 months ago

LifeOmic App Tools

Build
Status

Provides a set of utilities for developing custom web apps against the LifeOmic PHC API.

Installation

yarn install @lifeomic/app-tools

Using "Hosted" Authentication

import { LOAuth } from '@lifeomic/app-tools';

// Setup
const appAuth = new LOAuth({
  clientId: '<clientId>',
  authorizationUri:
    'https://lifeomic-prod-us.auth.us-east-2.amazoncognito.com/oauth2/authorize',
  accessTokenUri:
    'https://lifeomic-prod-us.auth.us-east-2.amazoncognito.com/oauth2/token',
  redirectUri: 'http://localhost:3000/callback',
  logoutUri: 'https://lifeomic-prod-us.auth.us-east-2.amazoncognito.com/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 { LOAuth } from '@lifeomic/app-tools';

const appAuth = new LOAuth({
  ...oauthConfig,
  storageKey: 'my-super-awesome-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 simply
const appAuth = new LOAuth({
  ...oauthConfig,
  storageKey: 'my-super-awesome-key',
  storage: sessionStorage
});

To opt-out of storing the token, you can pass in noop functions for storage

const noop = () => null;

const appAuth = new LOAuth({
  ...oauthConfig,
  storageKey: 'my-super-awesome-key',
  storage: {
    getItem: noop,
    setItem: noop,
    removeItem: noop
  }
});

Using API-based Authentication

import { APIBasedAuth } from '@lifeomic/app-tools';

// Setup
const auth = new APIBasedAuth({
  clientId: '<clientId>',
  storage: {
    // Provide a mechanism for storing + retrieving tokens.
  }
});

Passwordless Login

// Initiate login
await auth.initiatePasswordlessAuth({
  username: '<username-or-email>'
  appsBaseUri: 'use-bogus-value',
  loginAppBasePath: 'use-bogus-value',
});

// Confirm login using code
const res = await auth.confirmPasswordlessLogin({
  username: '<username-or-email>',
  code: '<code>'
})

res.accessToken;

Perform Custom App Token Exchange

const res = await auth.redeemCustomAppCode('<code>');

res.accessToken;
3.6.4

4 months ago

3.4.0

1 year ago

3.6.2

1 year ago

3.6.1

1 year ago

3.6.0

1 year ago

3.6.3

1 year ago

3.5.0

1 year ago

3.3.0

2 years ago

3.2.0

2 years ago

3.0.2

2 years ago

3.0.1

2 years ago

3.0.0

2 years ago

2.5.0

2 years ago

2.5.2

2 years ago

2.5.1

2 years ago

2.5.4

2 years ago

2.5.3

2 years ago

3.1.0

2 years ago

2.4.0

2 years ago

2.3.3

2 years ago

2.3.2

3 years ago

2.3.1

3 years ago

2.3.0

3 years ago

2.2.1

3 years ago

2.2.0

3 years ago

2.1.0

3 years ago

2.0.2

4 years ago

2.0.1

4 years ago

2.0.0

4 years ago

1.4.0

5 years ago

1.3.0

5 years ago

1.2.0

5 years ago

1.1.0

5 years ago

1.0.0

5 years ago

0.1.3

5 years ago

0.1.2

5 years ago