1. Jesper Trebbien
  2. PowerBuilder
  3. Thursday, 4 July 2024 10:02 AM UTC

Hello

I got a ps-script that can get a token. When trying similar in PB 2022 it returns -5 "Failed to get token".

Code pasted in below.

Any suggestions are appreciated.

BR

Jesper

 

Logan Liu @Appeon Accepted Answer Pending Moderation
  1. Friday, 5 July 2024 02:25 AM UTC
  2. PowerBuilder
  3. # 1

Hi Jesper,

You can try to use Fiddler or other tools to capture the HTTP traffic and check the response body.

E.g.: I can see this error from the Server after trying your code using an incorrect ClientSecret :

{"error":"unauthorized_client","error_description":"AADSTS700016: Application with identifier 'e3e65e1b-bcOf-4e02-b777-Oc94df554ed3' was not found in the directory 'AP Pension'. This can happen if the application has not been installed by the administrator of the tenant or consented to by any user in the tenant. You may have sent your authentication request to the wrong tenant. Trace ID: 401cf30c-9fe4-4184-811d-f0063a033400 Correlation ID: 6e170c8d-cdac-4130-b5ab-a07c561e77bc Timestamp: 2024-07-05 01:54:24Z","error_codes":[700016],"timestamp":"2024-07-05 01:54:24Z","trace_id":"401cf30c-9fe4-4184-811d-f0063a033400","correlation_id":"6e170c8d-cdac-4130-b5ab-a07c561e77bc","error_uri":"https://login.microsoftonline.com/error?code=700016"}

 

Not sure what error you will see if Itreq_Appeon.ClientSecret is correct. Please adjust it to the correct one and check the response body.

ring ls_tenant_id = "450da9d8-2bd5-4662-aa74-c622350537e5" // Directory (tenant) ID
String ls_token
String ls_body
Integer li_rc

RESTClient Irc_RestClient
Irc_RestClient = CREATE RESTClient

//Sets the token parameters
TokenRequest Itreq_Appeon

Itreq_Appeon.TokenLocation = "https://login.microsoftonline.com/"+ls_tenant_id+"/oauth2/v2.0/token"
Itreq_Appeon.Method = "post"
Itreq_Appeon.GrantType = "client_credentials"
Itreq_Appeon.ClientId = "e3e65e1b-bcOf-4e02-b777-Oc94df554ed3"
Itreq_Appeon.ClientSecret = "unknown"
Itreq_Appeon.Scope = "https://graph.microsoft.com/.default"
li_rc = Irc_RestClient.GetOauthtoken( Itreq_Appeon, ls_token)

Regards, Logan

Comment
There are no comments made yet.
Jesper Trebbien Accepted Answer Pending Moderation
  1. Thursday, 4 July 2024 12:52 PM UTC
  2. PowerBuilder
  3. # 2

Hi again 

With succes I have tried in Postman - and afterwards added the "Host" and "Content-Length" headers.

Then RestClient.GetOauthtoken returns -21. Unfortunately -21 isn't described in the documentation.

 

Code in Postman and PB:

Comment
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.