Issue || OAuth - JWT Bearer (Grant Type)

Kingstan M
Kilo Sage

Hello - SN.

 

Followed this doc = OAuth 2.0 credentials for GitHub Apps - JWT (servicenow.com)

Got details from GitHub end.

 

But when i try to refresh token i get this error 

OAuth flow failed. Verify the configurations and try again. Error detail:invalid_request, Missing parameters: access_token
 
I tried to log OAuth Util script 
 
 

 

//* Dont edit this script include. Best practise: Extend this script include and override the functions. 
var OAuthUtil = Class.create();
OAuthUtil.prototype = {
    initialize: function(oauthContext) {
        this.oauthContext = oauthContext;
    },

    interceptRequestParameters: function(requestParamMap) {
        // Add/Modify request parameters if needed
        this.preprocessAccessToken(requestParamMap);
    },

    parseTokenResponse: function(accessTokenResponse) {
        this.postprocessAccessToken(accessTokenResponse);
    },

    preprocessAuthCode: function(requestParamMap) {},

    preprocessAccessToken: function(requestParamMap) {},

    postprocessAccessToken: function(accessTokenResponse) {
        gs.log("kratos_wee accessTokenResponse.getContentType()===>" + accessTokenResponse.getContentType());
        gs.log("kratos_wee accessTokenResponse.getBody()====>" + accessTokenResponse.getBody());
        var contentType = accessTokenResponse.getContentType();
        if (contentType && contentType.indexOf('application/json') != -1) {
            var tokenResponse = (new global.JSON()).decode(accessTokenResponse.getBody());
            var paramMap = accessTokenResponse.getparameters();
            for (param in tokenResponse)
                paramMap.put(param, tokenResponse[param].toString());
        }
    },

    type: 'OAuthUtil'
};

 

I see the log over accessTokenResponse --below--

kratos_wee accessTokenResponse.getBody()====>{"message":"A JSON web token could not be decoded","documentation_url":"https://docs.github.com/rest"

kratos_wee accessTokenResponse.getContentType()===>application/json; charset=utf-8

 

Any advice?

 

Note : As per the OAuth 2.0 credentials for GitHub Apps - JWT (servicenow.com) i dont see OAuth API script = OAuthDevOpsGitHubJWTHandler. in the instance.

 

Many thanks.

 
11 REPLIES 11

Bharath Kumar A
Mega Sage

Hi @Kingstan M ,

 

Can you please try JSON.parse instead of decode method

From log i can see there is no obj key for accessTokenResponse

Do you have any adivce on this?

 

postprocessAccessToken: function(accessTokenResponse)

 

Bharath Kumar A
Mega Sage

accessTokenResponse itself is a obj parameter.

It has to be passed from either business rule or some other place where this script include is called.

can you provide details where you are calling this script include.

Ok good question.

But i dont use the OAuthilUtil script in the OAuth entity profile

 

I simply used the OAuthilUtil script and extended it with my custom script (The one i pasted in the question with log statements) for to see the behaiour.

So - I find the accessTokenResponse is empty thus i get this error.

 

But the config is all fine.

I created PEM file from git and used the given commands in the prod.doc to get JKS file.

Given config setup as per the doc.,

 

 

no_sinc.png