ROPC sample

Introduction

If you are building a non-web application that will use username and password for first-factor authentication, a simple way to obtain an access token or id token from IBM Security Verify is to use the OAuth 2.0 Resource Owner Password Credentials (ROPC) grant type.

To help you with this, we provide an easy-to-use JavaScript SDK which implements the Application part of the protocol. We also provide a sample command-line application which uses the SDK so you can see how to implement it.

In this guide you'll learn how to set up the sample application.

Prerequisites

You need to have registered an application using the Developer Portal in your IBM Security Verify tenant. See Using the Developer Portal for details. During registration, pick Resource owner password credentials (ROPC) as the grant type.

You need to have node.js installed on the system where you will run the sample application. Download node.js.

Download the sample application

  1. Access the Developer Portal of your IBM Security Verify tenant. Usually you will find this as a tile in the end user launchpad.

  2. From the My applications page, select your application and then click the App setup link that appears at the top of the details sidebar.

  3. Select the node.js tile.

  4. Select the Download app button. This will download a ZIP file containing the sample application.

1033

Download sample application

📘

This ZIP file contains customized content

The zip file you download here is specific to your environment. It contains a .env file which is pre-completed with your tenant ID and the clientid and client_secret for the registered application. The filename of this ZIP file is set based on the application name:
<app name>_-node-sample.zip

  1. Extract the ZIP file to the location where you will run the sample application.

Install modules

In the directory that was created when you extracted the ZIP file, run the following command to install the node modules required by the sample application:

npm install

added 9 packages, and audited 10 packages in 2s

found 0 vulnerabilities

Run the sample application and test

In the directory that was created when you extracted the ZIP file, run the following command to start the sample application:

npm start

> [email protected] start
> node ropc-sample.js

ibm-verify-sdk ROPC sample application


Authenticate against
tenant   : https://....verify.ibm.com
client ID: 0d6cc528-8fdc-4fa7-a66e-48f6191717e7


username: 

You can see that the application is running and has prompted for authentication.

Enter username and password

Enter the username and password of a user that exists in your IBM Security Verify tenant:

username: localadmin
password: **********

The user is authenticated against your IBM Security Verify tenant. If authentication fails, you will see the following message:

Authenticating...
Error occured while authenticating { error_description: 'CSIAQ0264E The user name or password is invalid.',
  error: 'invalid_grant' }

If authentication is successful, you will see information about the authenticated user. This information is being retrieved by calling the OIDC UserInfo endpoint using the access token retrieved using the ROPC grant type flow:

Authenticating...
Successfully authenticated


Retrieving user information...
Successfully retrieved user information


{ ext: { tenantId: '....verify.ibm.com' },
  sub: '123ABCPJ43',
  displayName: 'Scott Anderson',
  realmName: 'cloudIdentityRealm',
  uniqueSecurityName: '123ABCPJ43',
  name: 'Scott Anderson',
  userType: 'regular',
  preferred_username: 'sanderson' }

📘

Available attributes

The attributes that are shared from your IBM Security Verify tenant to the application are controlled by the requested OpenID Connect scopes and by the configuration of the Developer Portal (which is set by your tenant administrator).

If you want to receive additional information, try adding additional scopes to the .env file of the sample application:

SCOPE=openid profile email phone

What’s Next