OAuthAPI APIs

The OAuthAPI library provides functions for working with OAuth.

Table 1. Initialization functions
Function Description
Init( 
   cnx_timeout INTEGER, 
   client_id STRING,
   client_secret STRING )
  RETURNS BOOLEAN 
To be called in a Genero app accessing a secure RESTful Web service started behind a Genero Application Server.
InitService( 
   cnx_timeout INTEGER, 
   access_token STRING )
  RETURNS BOOLEAN 
To be called in a Genero web service started via OpenID Connect/OAuth2 accessing another secure RESTful web service as a client.
InitNativeApp(
  cnx_timeout INTEGER,
  tokens OpenIdCResponseType,
  client_id STRING,
  client_secret STRING,
  token_end_point STRING)
RETURNS BOOLEAN
To be called in a Genero mobile app accessing a secure RESTful web service directly (not behind a Genero Application Server).
Table 2. Metadata functions
Function Description
GetOpenIDMetadata()
RETURNS OAuthAPI.OpenIDMetadataType
Get metadata from the Identity Provider for a service running on a Genero Application Server (GAS).
Table 3. ID token metadata functions
Function Description
GetIDPIssuer()
RETURNS STRING
Get endpoint of the Identity Provider.
GetIdRoles()
RETURNS DYNAMIC ARRAY OF STRING
Get OAuth ID Token authorization roles.
GetIDScopes()
RETURNS DYNAMIC ARRAY OF STRING
Get OAuth ID Token authorization scopes.
GetIDSubject()
RETURNS STRING
Get OAuth subject identifier of ID Token.
Table 4. Access token functions
Function Description
GetMyAccessToken()
RETURNS STRING
Get a valid access token.
Table 5. Authorization request functions
Function Description
CreateHTTPAuthorizationRequest(
   url STRING )
RETURNS com.HttpRequest
Create an HttpRequest with OAuth access token.
RetryHTTPRequest(
resp com.HttpResponse )
RETURNS BOOLEAN
Retry an HttpRequest with OAuth access token to check if the access token has expired.
Table 6. Helper functions
Function Description
ExtractTokenFromHTTPRequest(
req comm.HttpServiceRequest)
RETURNS STRING
Return the OAuth access token.
FetchOpenIDMetadata(
   timeout INTEGER, 
   idp STRING )
RETURNS OAuthAPI.OpenIDMetadataType
Fetch metadata from the Identity Provider at the URL provided.
RetrievePasswordToken(
   timeout INTEGER,
   TokenServiceURL STRING, 
   usr, STRING, 
   pass STRING,
   scope STRING )
RETURNS ( STRING, INTEGER )
Return the OAuth service access token via user name and password.
RetrieveServiceToken(
   timeout INTEGER,
   TokenServiceURL STRING, 
   client_id STRING, 
   secret_id STRING,
   scope STRING )
RETURNS STRING, INTEGER
Return the OAuth service access token via client app credentials.
RetrievePasswordTokenForNativeApp(
  timeout INTEGER,
  TokenServiceURL STRING,
  username STRING,
  password STRING,
  client_id STRING,
  client_secret STRING,
  scope STRING)
RETURNS OpenIdCResponseType
Returns the OAuth service access token via user credentials (username/password) and client credentials (client_id/secret_id). A refresh token allows the access token to be refreshed when it expires.