Socket
Book a DemoInstallSign in
Socket

authenticus

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

authenticus

The simplest all-in-one authentication library for JavaScript.

4.1.1
latest
Source
npmnpm
Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

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:

  • Discord
  • GitHub
  • Google
  • Spotify

[!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'
  • Initialize client.

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

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

    const { accessToken } = await github.getToken({
      code: '...',
      redirectUri: 'https://example.com/oauth2/callback'
    })
    
  • 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>')

FAQs

Package last updated on 28 Apr 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.