4.1.1 • Published 4 days ago

authenticus v4.1.1

Weekly downloads
-
License
MIT
Repository
github
Last release
4 days ago

authenticus

authenticus is a all-in-one authentication library for Node.js, Deno, Cloudflare Workers, etc.

Setup

Node.js

npm i authenticus

Deno

deno.json

{
  "imports": {
    "authenticus": "https://esm.sh/authenticus@4.1.1"
  }
}

OAuth 2.0

Presets:

!IMPORTANT
You should wrap your code within a try...catch block, as each of the methods listed below can cause an AuthenticusError in some rare cases.

import { GitHub } from 'authenticus'
  1. Initialize client.

    const github = new GitHub({
      clientId: '...',
      clientSecret: '...',
      scopes: [
        'read:user',
        'user:email'
      ] // optional
    })
  2. Create a authorization url.

    const url = github.createAuthorizeUri({
      state: '...',
      allowSignup: true
    })
  3. Retrieve an access token.

    const { accessToken } = await github.getToken({
      code: '...',
      redirectUri: 'https://example.com/oauth2/callback'
    })
  4. Retrieve the user.

    const user = await github.getUser(accessToken)
    
    , normalizedUser = github.normalizeUser(user)

JWT

authenticus' JWT implementation is based on @timonson's djwt, which is available under the MIT license.

import { jwt } from 'authenticus'

jwt.sign(...)

Please refer to this page for a full guide.

OTP

authenticus' OTP implementation is based on @hectorm's otpauth, which is available under the MIT license.

import { otp } from 'authenticus'

// Generate a random secret.
const secret = otp.createRandomSecret()

// Create an URI for a QR code for Google Authenticator.
const uri = otp.createUri(secret, 'Issuer', 'Label')

// Get the current OTP.
const token = otp.createToken(secret)

// Check the validity of a token.
const result = otp.isValid(secret, '<token>')
4.1.1

4 days ago

4.1.0

2 months ago

4.0.1

2 months ago

4.0.0

2 months ago

2.0.2

9 months ago

3.0.0

5 months ago

2.0.1

10 months ago

2.0.0

10 months ago

1.0.0

11 months ago

0.0.0

1 year ago