v2.0.3
The simplest all-in-one authentication library for JavaScript.
Attributes
Includes Deno configuration
Repository
Current version released
a year ago
authenticus
Presets
-
Discord
-
GitHub
-
GitLab
-
Google
-
LinkedIn
-
Spotify
-
Twitch
Setup
🦕 Deno
import { createAuthorizeUrl, getToken, getUser, GitHub, preset, } from 'https://deno.land/x/authenticus@v2.0.0/mod.ts'
🐢 Node.js
npm i authenticus
import { createAuthorizeUrl, getToken, getUser, GitHub, preset, } from 'authenticus' // CommonJS const { GitHub, createAuthorizeUrl, getToken, getUser, preset } = require( 'authenticus', )
Usage
Create a Authorization URL
const url = createAuthorizeUrl(GitHub, { clientId: '...', scopes: ['read:user', 'user:email'], // optional allowSignup: true, })
Retrieve an Access Token
const { accessToken } = await getToken(GitHub, { clientId: '...', clientSecret: '...', code: '...', // part of the query string of the callback request redirectUri: 'https://example.com/oauth2/callback', })
Retrieve the User
const user = await getUser(GitHub, accessToken) // Retrieve a normalized user: const normalized = getNormalizedUser(GitHub, user)
Alternatively, you can specify the Client Secret and Client ID ahead of time:
Configure the preset.
const gh = preset({ ...GitHub, clientId: '...', clientSecret: '...', })
Create a Authorization URL
const url = createAuthorizeUrl(gh, { scopes: ['read:user', 'user:email'], // optional allowSignup: true, })
Retrieve an Access Token
const { accessToken } = await getToken(gh, { code: '...', // part of the query string of the callback request redirectUri: 'https://example.com/oauth2/callback', })
Retrieve the User
const user = await getUser(gh, accessToken) // Retrieve a normalized user: const normalized = getNormalizedUser(gh, user)
Known “Issues”
If you want to get the user for Twitch, you’ll need to provide the clientId
in
the function or set it beforehand.
// a)
const user = await getUser(GitHub, accessToken, { clientId: '...' })
// b)
const user = await getUser(gh, accessToken)