A client library for authenticating with the ISIC Archive from a SPA (single page application).
The ISIC client provides support for authenticating with the ISIC Archive using the Auth Code with PKCE flow of OAuth2.0.
$ 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();
});
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/