OAuthAPI.CreateHTTPAuthorizationRequest

Create an HTTPRequest with OAuth access token.

Syntax

CreateHTTPAuthorizationRequest(
   url STRING )
RETURNS com.HTTPRequest
  1. url is a STRING with the URL to connect to.

Returns a com.HTTPRequest object. NULL may be returned if the access token can not be renewed.

Usage

Use this function to create an HTTPRequest object with OAuth access token for access to a secure RESTful Web service.

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

OAuthAPI.CreateHTTPAuthorizationRequest function

IMPORT com
IMPORT FGL OAuthAPI

MAIN

DEFINE req com.HTTPRequest
DEFINE resp com.HTTPResponse
DEFINE url STRING

TRY
    # call the init function first

    # get request path
    LET url = fgl_getenv("OIDC_USERINFO_ENDPOINT")
 
    # Create oauth request
    LET req = OAuthAPI.CreateHTTPAuthorizationRequest(url)

    # Perform request
    CALL req.setMethod("GET")
    CALL req.setHeader("Accept", "application/json")
    CALL req.DoRequest()
        
    # Retrieve response
    LET resp = req.getResponse()

    # Process response
    CASE resp.getStatusCode()
        WHEN 200 #Success
        # ...
        OTHERWISE
            DISPLAY " Error code is: ",  resp.getStatusCode()
            EXIT PROGRAM 1
    END CASE
CATCH
    DISPLAY "ERROR : ",status,SQLCA.SQLERRM
    EXIT PROGRAM 1
END TRY

END MAIN