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

@marcosbv/ibmcloud-apikey-single-auth

v0.1.5

Published

Allows authentication to IBM Cloud platform and retrieval of IAM tokens and service credentials

Downloads

24

Readme

IBM Cloud API Key Single Auth Library

Implements a tiny client to authenticate to IBM Cloud Platform using API Keys.

The constructor will receive an Options object, that can be the following info:

  • apikey : API Key to authenticate to the authentication system
  • url: URL to authenticate to the authentication system

Both of parameters are optional. Environment variables IBMCLOUD_API_KEY and IBMCLOUD_IAM_URL can be used instead to give the library the needed information.

The main use case to use this library is authentication using service user IDs. In this approach, each service (in this context, service means a set of cloud resources to deliver a bunch of related features) can have a single Service User ID with the needed policies to access their cloud resources. An API Key is issued and used to access services. Two possible ways to access Cloud Resource APIs:

  • using IAM tokens (Watson services, Cloudant, COS buckets and many other IBM Cloud services have support to this)
  • using Service Credentials (IBM Cloud Databases, DB2, Blockchain Platform and others) - in this scenario, we can retrieve a Credential thru its name.

Usage

Below an example of usage:

const IBMCloudApikeyAuthClient = require('@marcosbv/ibmcloud-apikey-single-auth')

// instantiate a new client object 
const ibmcloudclient = new IBMCloudApikeyAuthClient({apikey: 'UJkTPJ548m8PtDGkP2ZumxEEvPwn-VVzLCvqxJjmF4w1'})

// issue a new token
ibmcloudclient.getToken().then((token) => {
    console.log(token)
})
/* output: eyJraWQiOiIyMDIwMDYyNDE4MzAiLCJhbGciOiJSUzI1NiJ9.eyJpYW1faWQiOiJpYW0tU2VydmljZUlkLTRlNDhiNGZiLTNjY2MtNDE0Mi1iMzQwLTE5OGVjNGFiZTdiZiIsImlkIjoiaWFtLVNlcnZpY2VJZC00ZTQ4YjRmYi0zY2NjLTQxNDItYjM0MC0xOThlYzRhYmU3YmYiLCJyZWFsbWlkIjoiaWFtIiwiaWRlbnRpZmllciI6IlNlcnZpY2VJZC00ZTQ4YjRmYi0zY2NjLTQxNDItYjM0MC0xOThlYzRhYmU3YmYiLCJuYW1lIjoiX2FwcC11c2FnZS1yZXBvcnQiLCJzdWIiOiJTZXJ2aWNlSWQtNGU0OGI0ZmItM2NjYy00MTQyLWIzNDAtMTk4ZWM0YWJlN2JmIiwic3ViX3R5cGUiOiJTZXJ2aWNlSWQiLCJhY2NvdW50Ijp7InZhbGlkIjp0cnVlLCJic3MiOiIzZTgxOTI2MGQ0ZjM0MGMwOTk5MjQwZTkwOWQ2MWEwOCJ9LCJpYXQiOjE1OTMyMDg1NDcsImV4cCI6MTU5MzIxMjE0NywiaXNzIjoiaHR0cHM6Ly9pYW0uY2xvdWQuaWJtLmNvbS9pZGVudGl0eSIsImdyYW50X3R5cGUiOiJ1cm46aWJtOnBhcmFtczpvYXV0aDpncmFudC10eXBlOmFwaWtleSIsInNjb3BlIjoiaWJtIG9wZW5pZCIsImNsaWVudF9pZCI6ImRlZmF1bHQiLCJhY3IiOjEsImFtciI6WyJwd2QiXX0.r7Jd0kKBR7llsDq_xroWqjVxkyoFG3CcRMbjY8WHjlDGw0rVYPTo3_ZAXBzdjthEyDYZUTmAlkt4j5ELUyhvIE3_Re90yi0wBDxZMggEbEOSd6Xq19ybBK13mG3pd4Q2ShWMVwPWBSU4IIFlado-bSBSSgqaVEmtbNOVbMAnQT5g3oCeruDdy5pxFjqJuxPgPqtraayFdpqn19ZqgPlRVHHWp1Cn3SDYaGHmGvZkJZkNs3pXlOpa4eWbcrjcTriFOsbOP9zvIHyY_M8M4_s78H7-RD_uhc_TvEvWedp5srMJcV5SJ0QYaO3aXrZ48sC1kbTlhVnt2rX6OH7z68hfxg
*/

ibmcloudclient.getServiceCredentialByName('My_PostgreSQL_Credentials').then((creds) => {
    console.log(creds)
})

/* output:
{ credentials:
   { connection: { cli: [Object], postgres: [Object] },
     instance_administration_api:
      { deployment_id:
         'crn:v1:bluemix:public:databases-for-postgresql:us-south:a/3e819260d4f340c0999240e909d61a08:5489566b-aa22-4e9b-9cc1-cc861f0b148a::',
        instance_id:
         'crn:v1:bluemix:public:databases-for-postgresql:us-south:a/3e819260d4f340c0999240e909d61a08:5489566b-aa22-4e9b-9cc1-cc861f0b148a::',
        root: 'https://api.us-south.databases.cloud.ibm.com/v4/ibm' } },
  status: 'SUCCESS' }
*/

getToken(force)

Get an IAM token. This token can be used to access several IBM Cloud API services, like Watson Services, Cloudant and so on. This method tries to cache the token in the memory until it expires.

force (optional): If a new token must be taken even there is a valid token in cache Returns a Promise with a Bearer Token as a String.

getServiceCredentialByName(key_name)

Gets a credential by Service Credential Name. It is important that the User that owns the API Key used in constructor has access to it.

key_name (required): Service Credential Name to look for. Returns a Promise with an object containing the following attributes:

  • status: NOT_FOUND or SUCCESS
  • credentials: Credentials to access the resource (its structure depends on the Cloud Service resource)
  • errorMessage: An error message if not successful.