1.0.3 • Published 3 years ago

auth0-access-token v1.0.3

Weekly downloads
-
License
ISC
Repository
-
Last release
3 years ago

auth0-access-token

Installation and Usage

npm install --save auth0-access-token

Grab your credentials from Auth0. You can find them on your Auth0 application settings page.

import AuthClient from 'auth0-access-token'

const authClient = new AuthClient({
    audience: 'YOUR_AUDIENCE'
    clientId: 'YOUR_CLIENT_ID'
    clientSecret: 'YOUR_CLIENT_SECRET'
    url: 'YOUR_AUTH0_URL/oauth/token'
  }
})

And then you can get your token with authClient.getToken()

Here's an example of how to get a token to use on a subsequent http request:

const fetchSecureData = async () => {
  const token = await authClient.getToken()

  axios({
    method: 'POST',
    url: '',
    headers: { authorization: `Bearer ${token}` },
    data: {...}
  })
}

API

InterfacesDescriptionParamsReturns
AuthClientConstructor method, use new keyword{audience, clientId clientSecret, url }client instance
client.getTokenFetches tokenemptyPromise<string>

Token request flow

image

Development

After you've made your changes to the package and pushed your branch, run:

npm version [patch|minor|major]

This will automatically bump up the version and push a new tag. If this is not done, the build will fail because npm doesn't allow publishing the same version twice. Make sure to follow semantic versioning.

Lastly, merge your PR and that check the drone build. If all goes well, it should automatically publish the new version to npm.

TODO:

Make it easier to test changes locally

1.0.3

3 years ago

1.0.2

3 years ago