This is the code in PowerBuilder:
// example from https://docs.appeon.com/pb2019r3/application_techniques/ch04s08.html
String ls_id, ls_secret, ls_Scope//, ls_Redirect
String ls_Body, ls_code, ls_Url_code, ls_AccessToken, ls_temp, ls_type, ls_description, ls_uri, ls_state
Integer li_rtn
OAuthClient loa_Client
TokenRequest ltr_Request
TokenResponse ltr_Response
OAuthRequest loa_Request
ResourceResponse lrr_Response
CoderObject lco_Code
Blob lb_data
lco_Code = Create CoderObject
loa_Client = Create OAuthClient
//Step 1: Get the authorization code
ls_code = is_altinn_code
If Len ( ls_code ) < 1 Then Return
lb_data = lco_Code.Urldecode( ls_code)
ls_code = String ( lb_data,EncodingANSI!)
//Step 2: Get the RESTful Server token
ltr_Request.ClearHeaders()
ltr_Request.tokenlocation = "https://test.idporten.no/token"
ltr_Request.SetHeader("Content-Type","application/x-www-form-urlencoded")
ltr_Request.Method = "POST"
ltr_Request.granttype = "authorization_code"
ltr_Request.clientid = is_client_id
ltr_Request.clientsecret = is_client_secret
ltr_Request.Scope = is_scope
ltr_Request.ClearParams()
//ltr_Request.AppendParam( "grant_type","authorization_code")
//ltr_Request.AppendParam( "client_id", is_client_id )
//ltr_Request.AppendParam( "client_secret", is_client_secret )
//ltr_Request.AppendParam( "scope", is_scope )
ltr_Request.AppendParam( "code", ls_code )
ltr_Request.AppendParam( "redirect_uri", is_redirect_url ) // what should this be??
li_rtn = loa_Client.AccessToken( ltr_Request, ltr_Response )
If li_rtn = 1 Then
ls_AccessToken = ltr_Response.GetAccessToken ( ) // Empty
messagebox("token", ls_accessToken)
ls_temp = string(ltr_response.getStatusCode()) // Empty
ls_temp = ltr_response.getStatusText() // Empty
li_rtn = ltr_response.getTokenError(ls_type, ls_Description, ls_uri, ls_state) // Empty
//Step 3: Get the RESTful Server resource
// If Len(ls_AccessToken) > 0 Then
// loa_Request.SetAccessToken (ls_AccessToken)
// loa_Request.Method = "GET"
// loa_Request.Url = "https://www.googleapis.com/oauth2/v1/tokeninfo" // what should this be???
// li_rtn = loa_Client.requestresource( loa_Request, lrr_Response )
// If li_rtn = 1 Then
// lrr_Response.GetBody(ls_Body)
// MessageBox ( "Tips", ls_Body )
// End If
// End If
End If
I have implemented this and I get the error code 401 - Unauthorized. I will contact the service vendor and check that the URL I am using is correct.
Thank you for your assistance!