OAuthAPI.InitService
To be called in a Genero Web service started via OpenID Connect accessing another secure RESTful Web service as a client.
Syntax
InitService(
cnx_timeout INTEGER,
access_token STRING )
RETURNS BOOLEAN
- cnx_timeout is a connection timeout from the REST service with value in seconds. The connection timeout is needed to avoid apps getting blocked by requests.
- access_token is the valid access token for accessing the RESTful Web service.
Returns FALSE
if the mandatory access token is null.
Usage
Use this function to register the access token to be used when a service (server side) has to connect (as a service client) to another service protected by an access token. It checks if the OAuth service is initiated.
The role of the function is to register the access token, so that you can then call any of the
OAuthAPI methods, such as CreateHTTPAuthorizationRequest
, to perform requests to the other service.
In case of error, a NULL
value will be returned.
In the code sample, the WSContext
dictionary is defined to get some information coming from the service configuration file
(.xcf).
The access token set during token validation to check access to the service is required to access
the client service. Therefore, you need to call InitService()
with it.
Typically, only the access token is required. If you need to get metadata, a call to
FetchOpenIDMetadata()
saves the metadata in an OpenIDMetadataType
record.
OAuthAPI.InitService function
IMPORT FGL OAuthAPI
PRIVATE DEFINE ctx DICTIONARY ATTRIBUTES(WSContext) OF STRING
MAIN
DEFINE metadata OAuthAPI.OpenIDMetadataType
DEFINE access_token STRING
DEFINE idp STRING
# retrieve access_token
LET access_token = ctx["OIDC_ACCESS_TOKEN"]
# retrieve IDP URL
LET idp = ctx["Parameter-IDP"]
# retrieve metadata
CALL OAuthAPI.FetchOpenIDMetadata(5,idp) RETURNING metadata.*
# Init OAuth service
IF NOT OAuthAPI.InitService(5, access_token) THEN
DISPLAY "Cannot initiate OAuth service"
END IF
CALL MyOtherService(access_token)
# ...
END MAIN