Skip to content

A JavaScript client for authenticating with the ISIC Archive via OAuth.

License

Notifications You must be signed in to change notification settings

ImageMarkup/isic-client

Repository files navigation

ISIC Client

A client library for authenticating with the ISIC Archive from a SPA (single page application).

npm (scoped)

Description

The ISIC client provides support for authenticating with the ISIC Archive using the Auth Code with PKCE flow of OAuth2.0.

Usage

$ npm install @isic/client

or if you're using yarn:

$ yarn add @isic/client
// create an isic client
// when running the app pass the CLIENT_ID as an environment var
const client = new IsicClient(process.env.CLIENT_ID);

// or, if connecting to the sandbox:
// const client = new IsicClient(process.env.CLIENT_ID, 'https://api-sandbox.isic-archive.com');
// handle the client signing in
document.querySelector('#sign-in-link').addEventListener('click', (event) => {
    event.preventDefault();
    client.redirectToLogin();
});
// load the proper token on each page load
let legacyToken;
client.maybeRestoreLogin()
  .then(() => {
    if (client.isLoggedIn) {
      return client.getLegacyToken();
    } else {
      return null;
    }
  })
  .then((_legacyToken) => {
    legacyToken = _legacyToken;
  })
// handle the client signing out
document.querySelector('#sign-out-link').addEventListener('click', (event) => {
    event.preventDefault();
    client.logout();
});

Example app

This repository comes bundled with an example application.

$ git clone [email protected]:ImageMarkup/isic-client.git
$ cd example
$ yarn install
$ yarn serve

# visit http://localhost:1234/