2.0.3 • Published 9 days ago

@authorizerdev/authorizer-js v2.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
9 days ago

Authorizer.js

@authorizerdev/authorizer-js is universal javaScript SDK for Authorizer API. It supports:

Migration Guide from 1.x -> 2.x

2.x version of @authorizerdev/authorizer-js has a uniform response structure that will help your applications to get right error codes and success response. Methods here have {data, errors} as response objects for methods of this library.

For 1.x version of this library you can get only data in response and error would be thrown so you had to handle that in catch.


All the above versions require Authorizer instance to be instantiated and used. Instance constructor requires an object with the following keys

KeyDescription
authorizerURLAuthorizer server endpoint
redirectURLURL to which you would like to redirect the user in case of successful login

Example

const authRef = new Authorizer({
  authorizerURL: 'https://app.herokuapp.com',
  redirectURL: window.location.origin,
});

IIFE

  • Step 1: Load Javascript using CDN
<script src="https://unpkg.com/@authorizerdev/authorizer-js/lib/authorizer.min.js"></script>
  • Step 2: Use the library to instantiate Authorizer instance and access various methods
<script type="text/javascript">
  const authorizerRef = new authorizerdev.Authorizer({
    authorizerURL: `AUTHORIZER_URL`,
    redirectURL: window.location.origin,
    clientID: 'YOUR_CLIENT_ID', // can be obtained from authorizer dashboard
  });

  // use the button selector as per your application
  const logoutBtn = document.getElementById('logout');
  logoutBtn.addEventListener('click', async function () {
    await authorizerRef.logout();
    window.location.href = '/';
  });

  async function onLoad() {
    const { data, errors } = await authorizerRef.authorize({
      response_type: 'code',
      use_refresh_token: false,
    });
    if (data && data.access_token) {
      // get user profile using the access token
      const { data: user, errors } = await authorizerRef.getProfile({
        Authorization: `Bearer ${res.access_token}`,
      });

      // 	logoutSection.classList.toggle('hide');
      // 	userSection.innerHTML = `Welcome, ${user.email}`;
    }
  }
  onLoad();
</script>

CommonJS

  • Step 1: Install dependencies
npm i --save @authorizerdev/authorizer-js
OR
yarn add @authorizerdev/authoirzer-js
  • Step 2: Import and initialize the authorizer instance
const { Authorizer } = require('@authorizerdev/authoirzer-js');

const authRef = new Authorizer({
  authorizerURL: 'https://app.heroku.com',
  redirectURL: 'http://app.heroku.com/app',
});

async function main() {
  await authRef.login({
    email: 'foo@bar.com',
    password: 'test',
  });
}

ES Modules

  • Step 1: Install dependencies
npm i --save @authorizerdev/authorizer-js
OR
yarn add @authorizerdev/authorizer-js
  • Step 2: Import and initialize the authorizer instance
import { Authorizer } from '@authorizerdev/authorizer-js';

const authRef = new Authorizer({
  authorizerURL: 'https://app.heroku.com',
  redirectURL: 'http://app.heroku.com/app',
});

async function main() {
  await authRef.login({
    email: 'foo@bar.com',
    password: 'test',
  });
}

Local Development Setup

Prerequisites

Setup

  • Clone the repository
  • Install dependencies using pnpm install
  • Run pnpm build to build the library
  • Run pnpm test to run the tests

Release

  • Run pnpm release to release a new version of the library
2.0.3

9 days ago

2.0.2

1 month ago

2.0.1

1 month ago

2.0.0

5 months ago

2.0.0-beta.2

5 months ago

2.0.0-beta.3

5 months ago

2.0.0-beta.1

5 months ago

2.0.0-beta.0

5 months ago

1.2.13

5 months ago

1.2.17

5 months ago

1.2.14

5 months ago

1.2.15

5 months ago

1.2.18

5 months ago

1.2.8

7 months ago

1.2.7

9 months ago

1.2.6

10 months ago

1.2.5

10 months ago

1.2.4

10 months ago

1.2.10

7 months ago

1.2.11

6 months ago

1.2.9

7 months ago

1.2.2-beta.2

1 year ago

1.2.2-beta.1

1 year ago

1.2.3

1 year ago

1.2.2

1 year ago

1.2.0

1 year ago

1.2.1

1 year ago

1.2.0-beta.1

1 year ago

1.2.0-beta.0

1 year ago

1.1.4-beta.0

1 year ago

1.1.6

1 year ago

1.1.5

1 year ago

1.1.4

1 year ago

1.1.2-beta.1

1 year ago

1.1.2-beta.0

1 year ago

1.1.1

2 years ago

1.1.3

1 year ago

1.1.2

1 year ago

1.0.1

2 years ago

1.0.0

2 years ago

1.1.0

2 years ago

0.17.0-beta.0

2 years ago

0.17.0-beta.1

2 years ago

0.11.0

2 years ago

0.13.0

2 years ago

0.13.1

2 years ago

0.15.0

2 years ago

0.14.0-beta.0

2 years ago

0.16.1-beta.0

2 years ago

0.12.0

2 years ago

0.14.0

2 years ago

0.14.1

2 years ago

0.16.0

2 years ago

0.16.1

2 years ago

0.13.0-beta.1

2 years ago

0.13.0-beta.2

2 years ago

0.4.0-beta.0

2 years ago

0.4.0-beta.1

2 years ago

0.4.0-beta.2

2 years ago

0.4.0-beta.3

2 years ago

0.5.0-beta.0

2 years ago

0.10.0

2 years ago

0.9.0

2 years ago

0.8.0

2 years ago

0.5.0

2 years ago

0.4.0

2 years ago

0.7.0

2 years ago

0.6.0

2 years ago

0.3.0

2 years ago

0.3.0-beta.0

2 years ago

0.2.1

2 years ago

0.2.0

2 years ago

0.1.0

2 years ago

0.1.0-beta.23

2 years ago

0.1.0-beta.20

3 years ago

0.1.0-beta.22

3 years ago

0.1.0-beta.18

3 years ago

0.1.0-beta.17

3 years ago

0.1.0-beta.19

3 years ago

0.1.0-beta.16

3 years ago

0.1.0-beta.15

3 years ago

0.1.0-beta.14

3 years ago

0.1.0-beta.13

3 years ago

0.1.0-beta.12

3 years ago

0.1.0-beta.11

3 years ago

0.1.0-beta.10

3 years ago

0.1.0-beta.9

3 years ago

0.1.0-beta.5

3 years ago

0.1.0-beta.7

3 years ago

0.1.0-beta.6

3 years ago

0.1.0-beta.8

3 years ago

0.1.0-beta.4

3 years ago

0.1.0-beta.3

3 years ago

0.1.0-beta.2

3 years ago

0.1.0-beta.1

3 years ago

0.1.0-beta.0

3 years ago