Error when trying to generate Oauth token

Andrei Radules1
Giga Contributor

Hello, 

I am sometimes receiving the following error when trying to get a new Oauth Token via ScriptL

"

org.apache.commons.httpclient.HttpException: CertPathValidatorException
Invalid null response.: no thrown error
OAuthProblemException{error='Invalid null response.', description='', uri='null', state='null', scope='null', redirectUri='null', responseStatus=0, parameters={}}
*** Script: [DEBUG] null // access token
*** Script: [DEBUG] 0 // expiry time
*** Script: [DEBUG] null // refresh token

"

The script that I am using is:
"
var oAuthClient = new sn_auth.GlideOAuthClient();

var params = {grant_type:"password", username:'username', password:'password'};

var json = new global.JSON();

var text = json.encode(params);

var tokenResponse = oAuthClient.requestToken('OAuth_Final_Client', text);

var token = tokenResponse.getToken();

var access_token = token.getAccessToken();

var token_expires = token.getExpiresIn();

var refresh_token = token.getRefreshToken();

gs.debug(access_token);
gs.debug(token_expires);
gs.debug(refresh_token);

"

The weird thing is that sometimes it works, sometimes it does not, seems to be very inconsistent and random when it wants to work.

Any ideas ?

Thank you !
5 REPLIES 5

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Andrei,

Did you notice any pattern when it doesn't work?

like from few users session it works and from others it doesn't

check the below links:

https://community.servicenow.com/community?id=community_question&sys_id=21c387a5dbd8dbc01dcaf3231f96...

https://community.servicenow.com/community?id=community_question&sys_id=32100f21db98dbc01dcaf3231f96...

Regards

Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Unfortunately no patterns, not sure if it is a problem with the Oauth provider/client or with the script.

Aksha
Tera Guru

Not sure about this scenario. I created an Outbound REST Message for generating OAuth token and is working without any failure.

Please let me know if you need help in generating token via Outbound Rest Message

Hello,

I did not consider thap option but could be a good idea.

Can you please let me know how you set up the REST Message and how it handles the access/refresh tokens lifepsan ?


Thank you for the help !