OAuthAPI.RetrievePasswordToken

Return the OAuth service access token via user name and password.

Syntax

RetrievePasswordToken(
   timeout INTEGER,
   TokenServiceURL STRING, 
   usr, STRING, 
   pass STRING,
   scope STRING )
RETURNS ( STRING, INTEGER )
  1. timeout. Defines the number of seconds.
  2. TokenServiceURL. This is the token endpoint of the Identity Provider (IdP) securing the service.
  3. usr. This is the user's login details.
  4. pass. This is the user password.
  5. scope. This is a space-separated list of scopes defining user access.

Returns a valid access token and when it expires in seconds. NULL may be returned if the access token is not available.

Usage

Use this function to retrieve a valid access token for a client app accessing a RESTful Web service using the username and password.

In case of error, a NULL value will be returned.

OAuthAPI.RetrievePasswordToken function

IMPORT FGL OAuthAPI

MAIN

DEFINE metadata OAuthAPI.OpenIDMetadataType
DEFINE token  STRING
DEFINE expire INTEGER
DEFINE usr, pass, STRING
DEFINE scope STRING
DEFINE idp_url STRING

TRY
     # ...
     CALL OAuthAPI.FetchOpenIDMetadata(20, idp_url)
          RETURNING metadata.*
     IF metadata.issuer IS NULL THEN
         ERROR "IdP not available" 
         EXIT PROGRAM 1
     ELSE
        CALL OAuthAPI.RetrievePasswordToken(5, metadata.token_endpoint, usr, pass, scope ) 
           RETURNING token, expire
        IF token IS NULL THEN
           DISPLAY "Unable to retrieve token"
           EXIT PROGRAM 1
        ELSE
            DISPLAY "Access token value :",token 
            DISPLAY SFMT("Token expires in %1 seconds",expire)
        END IF
     END IF
CATCH
   DISPLAY "ERROR : ",status,SQLCA.SQLERRM
   EXIT PROGRAM 1
END TRY

END MAIN