@lazy/oauth2-implicit-grant-client
TypeScript icon, indicating that this package has built-in type declarations

1.0.0-rc.3 • Public • Published

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, or redirect_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()

Package Sidebar

Install

npm i @lazy/oauth2-implicit-grant-client

Weekly Downloads

0

Version

1.0.0-rc.3

License

MIT

Unpacked Size

9.38 kB

Total Files

6

Last publish

Collaborators

  • aidant