Git Product home page Git Product logo

predix-uaa-client's Introduction

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

Use client credentials to get a bearer token.

NOTE: 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.

NOTE: This 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);
});

predix-uaa-client's People

Contributors

gstroup avatar orendin avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.