Lazy Oauth2 Implicit Grant Client
A simple Oauth2 Implicit Grant client for the lazy developer.
Table of Contents
Example
import { getAccessToken, handleImplicitGrantCallback } from '@lazy/oauth2-implicit-grant-client'
handleImplicitGrantCallback()
const token = await getAccessToken('https://api.example.com/authorize', {
client_id: 'example-client-id',
})
API
getAccessToken
The getAccessToken
function handles the Implicit Grant authentication flow. A new window is created where the user is then prompted to authenticate with the Oauth2 provider, once the user had accepted or rejected the request the handleImplicitGrantCallback
function then handles the response and returns it back via the promise from getAccessToken
- just like magic.
Parameters
-
endpoint
- string - The Authorization endpoint of the Oauth2 provider. -
parameters
- object - The Oauth2 parameters such as;client_id
,scope
, orredirect_uri
.
Example
import { getAccessToken } from '@lazy/oauth2-implicit-grant-client'
const token = await getAccessToken('https://api.example.com/authorize', {
client_id: 'example-client-id',
})
Returns Promise<string>
handleImplicitGrantCallback
The handleImplicitGrantCallback
function is responsible for returning the response from the authentication endpoint back to the getAccessToken
function. If you call the getAccessToken
and handleImplicitGrantCallback
functions in the same page make sure you call the handleImplicitGrantCallback
function before the getAccessToken
.
Example
import { handleImplicitGrantCallback } from '@lazy/oauth2-implicit-grant-client'
handleImplicitGrantCallback()