Written by

Question Nezla · Mar 12, 2024

Get JWT Token

Hi Guys,

I'm trying both of these methods to get a JWT token but none is working for some reason and not sure what I'm missing?

it works when I tested it from Postman 

Thanks

Product version: Ensemble 2018.1

Comments

Nezla  Mar 12, 2024 to Luis Angel Pérez Ramos

No errors, tSc returned as null, which I guessing that the post didn't go through because I'm doing something wrong in my code?

0
David Hockenbroch  Mar 12, 2024 to Nezla

If it's null, your code might not even be getting to the Post method. Are you running this in the terminal, and are you getting any other errors there? Is your RTLS SSL configuration set up in the management portal?

Also, when the response comes back, it's JSON, so if you want to get just the token, you'd have to:

set tokenObj = ##class(%Library.DynamicObject).%FromJSON(AuthToken.HttpResponse.Data)
set AuthTokenValue = tokenObj.%Get("access_token")

0
Nezla  Mar 12, 2024 to David Hockenbroch

Yep exactly, getting null means that my post might not even get there and I'm trying to find out the reason.
Yes RTLS is configured in SSL and I'm actually using it in other place for other clients and working fine but not with this client?
Thanks

0
Lucas Cristofolini · Mar 12, 2024

Hello @Nezla 

Are you using the HTTP adapter? If so, try using the ..Adapter.SendFormData(.tHttpResponse,"POST",tHttpRequest,,,tURL) method. Your URL will be your server concatenated with the path, which in your case you are setting directly in the POST method.

0
Nezla  Mar 12, 2024 to Lucas Cristofolini

Haven't used HTTP adapter before, any sample on how to use it ?

0
Nezla  Mar 13, 2024 to Lucas Cristofolini

when I try it from the Terminal I get the following error:

0
Lucas Cristofolini  Mar 13, 2024 to Lucas Cristofolini

I saw the #Ensemble tag, so I thought you were using a Business Operation. Another thing I noticed is that you are not setting the server port that will be called.

0
Nezla  Mar 13, 2024 to Lucas Cristofolini

Thanks, our client didn't recommended a specific port and it worked fine from Postman without it, but now I've set the default port 443 and still the same error?
  

0
Nezla · Mar 13, 2024

when I try it from the Terminal I get the following error:

0
Shakthi  Apr 15, 2024 to Nezla

I believe you have to post excluding the domain name in the URL (As you already specified domain under Server property of HttpRequest object).  From your terminal screenshot , try like below ?

set tSc=AuthToken.Post("/B2C_1A_client_credentials_signIn/oauth2/v2.0/token?ptid=.........")
0
David Hockenbroch  Apr 16, 2024 to Shakthi

If that's the issue, you could also try the following, and it will post to that location using the parameters you specified with InsertFormData:

set AuthToken = "/B2C_1A_client_credentials_signIn/oauth2/v2.0/token"set tSc = AuthToken.Post()
0