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

predix-uaa-client

v1.3.7

Published

Node module to get a token from UAA using client credentials or refresh tokens

Downloads

1,960

Readme

predix-uaa-client

Node module to get a token from UAA using client credentials or a refresh token.

Usage

Install via npm

npm install --save predix-uaa-client

This package can be used in various ways, depending on the params passed into the getToken function.

Use client credentials to get a bearer token.

In this mode, no refresh token is passed in. This call can be made for each outgoing request. The library will cache the token until expiry, so subsequent calls will resolve instantaneously.

const uaa_util = require('predix-uaa-client');
// Call with client credentials (UAAUrl, ClientID, ClientSecret),
// will fetch a client token using these credentials.
// In this case the client needs authorized_grant_types: client_credentials
uaa_util.getToken(url, clientId, clientSecret).then((token) => {
    // Use token.access_token as a Bearer token Authroization header
    // in calls to secured services.
    request.get({
        uri: 'https://secured.service.example.com',
        headers: {
            Authorization: 'Bearer ' + token.access_token
        }
    }).then((data) => {
        console.log('Got ' + data + ' from service');
    }).catch((err) => {
        console.error('Error getting data', err);
    });
}).catch((err) => {
    console.error('Error getting token', err);
});

Use a refresh token get a new access_token for a user.

When passing a refresh token, the function will NOT cache, this should only be called when a new user access token is required.

const uaa_util = require('predix-uaa-client');
// Call with client credentials (UAAUrl, ClientID, ClientSecret, RefreshToken),
// will fetch an access token for the user represented by the refresh token.
// In this case the client needs authorized_grant_types: refresh_token
uaa_util.getToken(url, clientId, clientSecret, refreshToken).then((token) => {
    // New access token is in token.access_token.
    // New refresh token is in token.refresh_token.
    console.log('New access token', token.access_token);
    console.log('New refresh token', token.refresh_token);
    console.log('New access token expires at', token.expire_time);
}).catch((err) => {
    console.error('Error getting token', err);
});

Request scopes if a token with particular scopes (ex. authZ permisions) is required.

The 5th parameter is passed as a comma separated string of scopes.

const uaa_util = require('predix-uaa-client');
// Call with client credentials (UAAUrl, ClientID, ClientSecret, null, scopes),
// will fetch an access token for the user with requested scopes.
// In this case the client needs authorized_grant_types: refresh_token
uaa_util.getToken(url, clientId, clientSecret, null, 'scope1,scope2').then((token) => {
    // New access token is in token.access_token.
    // New refresh token is in token.refresh_token.
    console.log('New access token', token.access_token);
    console.log('New refresh token', token.refresh_token);
    console.log('New access token expires at', token.expire_time);
}).catch((err) => {
    console.error('Error getting token', err);
});