-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8866c61
commit ca94d25
Showing
1 changed file
with
22 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,10 @@ It supports: | |
- [CommonJS(cjs)](https://flaviocopes.com/commonjs/) build for NodeJS version that don't support ES Modules | ||
- [ESM (ES Modules)](https://hacks.mozilla.org/2018/03/es-modules-a-cartoon-deep-dive/) build for modern javascript standard, i.e. ES Modules | ||
|
||
# Migration 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 object for methods of this library | ||
|
||
All the above versions require `Authorizer` instance to be instantiated and used. Instance constructor requires an object with the following keys | ||
|
||
| Key | Description | | ||
|
@@ -18,7 +22,7 @@ All the above versions require `Authorizer` instance to be instantiated and used | |
|
||
```js | ||
const authRef = new Authorizer({ | ||
authorizerURL: "https://app.herokuapp.com", | ||
authorizerURL: 'https://app.herokuapp.com', | ||
redirectURL: window.location.origin, | ||
}); | ||
``` | ||
|
@@ -38,22 +42,22 @@ const authRef = new Authorizer({ | |
const authorizerRef = new authorizerdev.Authorizer({ | ||
authorizerURL: `AUTHORIZER_URL`, | ||
redirectURL: window.location.origin, | ||
clientID: "YOUR_CLIENT_ID", // can be obtained from authorizer dashboard | ||
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 () { | ||
const logoutBtn = document.getElementById('logout'); | ||
logoutBtn.addEventListener('click', async function () { | ||
await authorizerRef.logout(); | ||
window.location.href = "/"; | ||
window.location.href = '/'; | ||
}); | ||
async function onLoad() { | ||
const res = await authorizerRef.authorize({ | ||
response_type: "code", | ||
const { data, errors } = await authorizerRef.authorize({ | ||
response_type: 'code', | ||
use_refresh_token: false, | ||
}); | ||
if (res && res.access_token) { | ||
if (data && data.access_token) { | ||
// get user profile using the access token | ||
const user = await authorizerRef.getProfile({ | ||
Authorization: `Bearer ${res.access_token}`, | ||
|
@@ -80,17 +84,17 @@ yarn add @authorizerdev/authoirzer-js | |
- Step 2: Import and initialize the authorizer instance | ||
|
||
```js | ||
const { Authorizer } = require("@authorizerdev/authoirzer-js"); | ||
const { Authorizer } = require('@authorizerdev/authoirzer-js'); | ||
|
||
const authRef = new Authorizer({ | ||
authorizerURL: "https://app.heroku.com", | ||
redirectURL: "http://app.heroku.com/app", | ||
authorizerURL: 'https://app.heroku.com', | ||
redirectURL: 'http://app.heroku.com/app', | ||
}); | ||
|
||
async function main() { | ||
await authRef.login({ | ||
email: "[email protected]", | ||
password: "test", | ||
email: '[email protected]', | ||
password: 'test', | ||
}); | ||
} | ||
``` | ||
|
@@ -108,17 +112,17 @@ yarn add @authorizerdev/authorizer-js | |
- Step 2: Import and initialize the authorizer instance | ||
|
||
```js | ||
import { Authorizer } from "@authorizerdev/authorizer-js"; | ||
import { Authorizer } from '@authorizerdev/authorizer-js'; | ||
|
||
const authRef = new Authorizer({ | ||
authorizerURL: "https://app.heroku.com", | ||
redirectURL: "http://app.heroku.com/app", | ||
authorizerURL: 'https://app.heroku.com', | ||
redirectURL: 'http://app.heroku.com/app', | ||
}); | ||
|
||
async function main() { | ||
await authRef.login({ | ||
email: "[email protected]", | ||
password: "test", | ||
email: '[email protected]', | ||
password: 'test', | ||
}); | ||
} | ||
``` | ||
|