2.0.1 • Published 12 months ago

@nuskin/service-token v2.0.1

Weekly downloads
-
License
MIT
Repository
-
Last release
12 months ago

@nuskin/service-token

This library is used to create a new NextGen Service Token. The token created is a JSON Web Token (JWT). For additional information about JSON Web Tokens, click here.

Note: This package was previously published under the @nextgen scope as @nextgen/service-token. It has now moved to the @nuskin scope. Please update your dependencies accordingly.

Installing

Using yarn:

yarn add @nuskin/service-token

Example usage

const { decodeJWT, isTokenStale, getServiceToken } = require('@nuskin/service-token')

const clientId = 'myFakeId'
const clientSecret = 'myFakeSecret'
const tokenUrl = 'https://the-token-store.com/some-endpoint'
const scopes = [
    'internal:fake:read',
    'internal:fake:write'
]

try {
    // create a new token with desired scopes
    const token = await getServiceToken(clientId, clientSecret, tokenUrl, scopes)

    // check if the token is stale
    if(isTokenStale(token)){
        // the token is stale and I should do something here if it is stale.
    }

    // decode the token
    console.log(decodeJWT(token))

} catch (error){
    console.error(error)
}

Resources

SDK Documentation not currently published

License

MIT

2.0.1

12 months ago

2.0.0

12 months ago