npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@cadolabs/auther-client

v1.0.0

Published

Client for working with auther on the frontend side

Downloads

687

Readme

@cadolabs/auther-client ·

A frontend client for working with the Auther gem.

Getting Started

Installation

npm i @cadolabs/auther-client

or

yarn add @cadolabs/auther-client

Configure

Create an AutherClient instance before initializing your application.

import { AutherClient } from "@cadolabs/auther-client"

const auth = AutherClient.init({
  autherUrl: "<AUTHER_DOMAIN>",
  redirectUri: "<CALLBACK_URL>",
  appcode: "<APP_CODE>", // your app unique id
})

Usage

Logging In

To redirect to the auther login

auth.login()

And after that you redirect to the callback route <CALLBACK_URL> with query string authorization_code="12345".

Get tokens

//async/await
try {
  const authorizationCode = "12345"

  const response = await auth.fetchTokens(authorizationCode) // return Promise
  const tokens = response.json()

  const { accessToken, refreshToken } = tokens
  ...
} catch (error) {
  throw Error(error.message) // invalid.authorization_code
}

Update tokens

const refreshToken = "refresh_token"

//async/await
try {
  const response = await auth.updateTokens(refreshToken) // return Promise
  const tokens = response.json()

  const { accessToken, refreshToken } = tokens
} catch (error) {
  throw Error(error.message) // invalid.access_token
}

Loggout In

To make a request to revoke tokens

const accessToken = "access_token"

//async/await
try {
  await auth.logout(accessToken)
  ...
} catch (error) {
  throw Error(error.message) // invalid.access_token
}

Authentication

Authentication method for verifying access and refresh tokens and scheduling tokens refreshing.

const getTokens = () => {
  const accessToken = localStorage.getItem("accessToken")
  const refreshToken = localStorage.getItem("refreshToken")

  return { accessToken, refreshToken }
}

const saveTokens = ({ accessToken, refreshToken }) => {
  localStorage.setItem("accessToken", accessToken)
  localStorage.setItem("refreshToken", refreshToken)
}

//async/await
try {
  await auth.authentication({ getTokens, saveTokens })
  ...
} catch (error) {
  throw Error(error.message) // token.not_found
}

Additional usage

Decode token

To decode the token

import { decode } from "@cadolabs/auther-client"

const testToken = "eyJhbGc*.NHVaY*.i8ZJd8_-RU8V" // headers.payload.signature

const decodedToken = decode(testToken)

console.log(decodedToken)

/* console prints:
 * {
 *   header: {
 *     alg: "RS256",
 *     typ: "JWT"
 *   },
 *   payload: {
 *     sub: "1234567890",
 *     name: "John Doe",
 *     iat: 1516239022,
 *     exp: 1516239022,
 * },
 *   signature: "i8ZJd8_-RU8V",
 * }
*/

Return the decoded object with parameters

Verify token

Checks the token for errors or expired time. If there are no problems, return it back

import { verify } from "@cadolabs/auther-client"

const testToken = "eyJhbGc*.NHVaY*.i8ZJd8_-RU8V" // headers.payload.signature

try {
  const verifiedToken = verify(testToken)

  console.log(verifiedToken)

  /* console prints if no problems:
  * "eyJhbGc*.NHVaY*.i8ZJd8_-RU8V"
  */
} catch (error) {
  console.log(error.message)
  /* console prints if token is expired:
  * "token.expired"
  */
}

Contributing

  • Fork it ( https://github.com/Cado-Labs/auther-client )
  • Create your feature branch (git checkout -b feature/my-new-feature)
  • Commit your changes (git commit -am '[feature_context] Add some feature')
  • Push to the branch (git push origin feature/my-new-feature)
  • Create new Pull Request

License

Released under MIT License.

Supporting

Authors

Sergey Andreev