Skip to main content


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

  1. Create a Authorization URL

    const url = createAuthorizeUrl(GitHub, {
      clientId: '...',
      scopes: ['read:user', 'user:email'], // optional
      allowSignup: true,
    })
  2. 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',
    })
  3. 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:

  1. Configure the preset.

    const gh = preset({
      ...GitHub,
      clientId: '...',
      clientSecret: '...',
    })
  2. Create a Authorization URL

    const url = createAuthorizeUrl(gh, {
      scopes: ['read:user', 'user:email'], // optional
      allowSignup: true,
    })
  3. 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',
    })
  4. 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)