OAuthAPI.InitService
To be called in a Genero web service started via OpenID Connect/OAuth2 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 to the REST service with value in seconds.
- 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 the same
token.
Typically, only the access token is required. If you need to get metadata, a call to
FetchOpenIDMetadata()
saves the metadata in an c_gws_oauthapi_types.html#c_gws_oauthapi_types__row_OpenIDMetadataTypeOpenIDMetadataType
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