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 🙏

© 2026 – Pkg Stats / Ryan Hefner

decentraland-auth

v0.12.0

Published

JavaScript client for the auth-service

Readme

decentraland-auth

JavaScript client for the auth-service

Installation

$ npm i decentraland-auth

Usage

Create an Auth instance, login and then get access tokens whenever you need them

import { Auth } from 'decentraland-auth'

const auth = new Auth()
const userToken = await auth.login() // prompts the user to login

const accessToken = await auth.getAccessToken() // returns a valid access token
const { user_id } = await auth.getAccessTokenData() // returns access token payload data

Send signed request

const auth = new Auth()
await auth.login()

// GET
const request = await auth.createRequest(
  'some-service.decentraland.org/path?query=param'
)
const response = await fetch(request)

// POST
const request = await auth.createRequest(
  'some-service.decentraland.org/do-something',
  {
    method: 'post',
    headers: {
      'Some-Header': 'bla bla'
    },
    body: JSON.stringify({ param: 'asdf' })
  }
)
const response = await fetch(request)

Generate credentials for message

const auth = new Auth()
const userToken = await auth.login()

const msg = 'hi there!' // it could also be a null

const credentials = await auth.getMessageCredentials(msg)

This library makes use of Buffer, which is not present natively in the browser. There's a polyfill that is included by default by some bundlers (like webpack), but if you don't have it make sure to add it to your project: Buffer.

API

  • new Auth([options]): Returns a new instance of Auth. It takes an optional options objects that can contain the following properties:

    • ephemeralKeyTTL: Time to live for the ephemeral key (in seconds). Default value is 60 * 60 * 2 (2 hours).

    • api: An object with options for the underlying API instance:

      • baseURL: The base url of the auth-service. Default value is https://auth.decentraland.zone/api/v1.

      • loginCallback: The login callback url. It defaults to /callback.

      • logoutCallback: The logout callback url. It defaults to /.

  • auth.login([target]): Returns a promise that will resolve once the user is logged in. The first time it's called it will prompt the user to login though a Popup. If a target dom node is provided, instead of a Popup it will insert an iframe inside the target node and use that. If the user closes the Popup the promise will reject. If the user session is still active this method might resolve without having to open a popup.

  • auth.isLoggedIn(): Returns a boolean telling wheter the user is logged in or not.

  • auth.getAccessToken(): It returns a promise that resolves to an access token. This access token has a short life so it is recommended to get a new token every time you need to use is instead of storing it.

  • auth.getAccessTokenData(): It returns a promise that resolves to the payload of the access token (basically the decoded JWT).

  • auth.logout(): It returns a promise that resolves once the user is logged out. After using this, the next time the login() method is called it will prompt the user with the login flow.

  • auth.createRequest(url, options?): It returns a promise that resolves to a Request object that can be used with fetch. It takes a URL and the same options as fetch.

  • auth.createHeaders(url, options?): It returns a promise that resolves to an object containing the mandatory headers to be used in a signed request. It takes a URL and the same options as fetch.

  • auth.getUserToken(): It returns a promise that resolves to the userToken. This token is the one used to generate the accessToken(s).

  • auth.getEphemeralKey(): Returns the instance of the ephemeral key.

  • auth.dispose(): It removes all the bindings on this instance. It does NOT perform a logout.