0.1.3-rc8 • Published 4 years ago

pwa-rpc v0.1.3-rc8

Weekly downloads
1
License
MIT
Repository
-
Last release
4 years ago

pwa-rpc

Description

A simple JavaScript library which provides PWA's the ability to retrieve OAuth tokens and their related information from PACE native apps.

Installation

As NPM package

yarn add pwa-rpc

or

npm i pwa-rpc

Usage

// OAuthApp.js
import OAuthApplication from 'pwa-rpc';

const OAuthApp = new OAuthApplication({
  clientId: 'my_client_id',
  disableRemoteDiagnostics: false, //optional, default is false
  scope: 'my_scope',
});

export async function getAccessToken() {
  try {
    const token = await OAuthApp.getAccessToken();
    const { access_token } = token;
    return access_token;
  } catch (e) {
    // Handle error
  }
}

export async function getQueryParamValue(key) {
  try {
    const queryParam = await OAuthApp.getQuery(key);
    return queryParam;
  } catch (e) {
    // Handle error
  }
}

export function close() {
  OAuthApp.close();
}


// API.js
import { getAccessToken } from '../OAuthApp';

async function makeAPICall() {
  try {
    const accessToken = await getAccessToken();
    let response = await fetch(url, {
      method: 'GET',
      headers: {
        Authorization: `Bearer ${accessToken}`,
      },
    });
    let responseJSON = await response.json();
    // Do sth with responseJSON
  } catch (error) {
    // Handle error
  }
}

License

MIT

0.1.3-rc8

4 years ago

0.1.3-rc7

4 years ago

0.1.3-rc6

4 years ago

0.1.3-rc5

4 years ago

0.1.3-rc4

4 years ago

0.1.3-rc3

4 years ago

0.1.3-rc2

4 years ago

0.1.3-rc1

5 years ago

0.1.2-rc1

5 years ago

0.1.2

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago