OAuthAPI.RetryHTTPRequest

Retry an HTTPRequest with OAuth access token to check if the access token has expired.

Syntax

RetryHTTPRequest(
resp com.HTTPResponse )
RETURNS BOOLEAN
  1. resp is a com.HTTPResponse object.

Returns TRUE if the access token has expired and the request must be sent again, FALSE otherwise.

Usage

Use this function to check whether the access token to a secure RESTful Web service has expired. If expired, it will perform the refresh and then do the request.

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

OAuthAPI.RetryHTTPRequest function

IMPORT com
IMPORT FGL OAuthAPI

MAIN

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

TRY

    # Get path
    LET url = fgl_getenv("OIDC_USERINFO_ENDPOINT")

    WHILE TRUE
        # 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()
        # Retry if access token has expired
        IF NOT OAuthAPI.RetryHTTPRequest(resp) THEN
           EXIT WHILE
        END IF   
    END WHILE

    # 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