$ npm i decentraland-auth
Auth instance, login and then get access tokens whenever you need them
Send signed request
await auth.login// GET// POST
Generate credentials for message
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.
new Auth([options]): Returns a new instance of
Auth. It takes an optional
optionsobjects 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
baseURL: The base url of the
auth-service. Default value is
loginCallback: The login callback url. It defaults to
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
targetdom 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
Requestobject that can be used with
fetch. It takes a URL and the same options as
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
auth.getUserToken(): It returns a promise that resolves to the
userToken. This token is the one used to generate the
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.