OAuthAPI.RetrieveServiceToken
Return the OAuth service access token via client app credentials.
Syntax
RetrieveServiceToken(
timeout INTEGER,
TokenServiceURL STRING,
client_id STRING,
secret_id STRING,
scope STRING )
RETURNS STRING, INTEGER
- timeout. Defines the number of seconds.
- TokenServiceURL. This is the token endpoint of the Identity Provider (IdP) securing the service.
- client_id. This is the application ID assigned to the app when registered.
- client_secret. This is the application secret created for the app.
- 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 client app's own client id and client secret credentials.
In case of error, a NULL
value will be returned.
OAuthAPI.RetrieveServiceToken function
IMPORT FGL OAuthAPI
MAIN
DEFINE metadata OAuthAPI.OpenIDMetadataType
DEFINE token STRING
DEFINE expire INTEGER
DEFINE client_id STRING
DEFINE secret_id 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.RetrieveServiceToken(5, metadata.token_endpoint, client_id, secret_id, 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