Skip to content

Instantly share code, notes, and snippets.

@jnerius
Last active November 18, 2022 19:16
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jnerius/0e639c09f7708ef3bdf15f264375dd6c to your computer and use it in GitHub Desktop.
Save jnerius/0e639c09f7708ef3bdf15f264375dd6c to your computer and use it in GitHub Desktop.
ServiceNow OAuth Handler Script Include for processing OAuth Responses from GitHub
var OAuthGitHubHandler = Class.create();
OAuthGitHubHandler.prototype = Object.extendsObject(OAuthUtil, {
// Override postprocessAccessToken method. GitHub returns a urlencoded
// body, so we need to break this apart and extract the values.
postprocessAccessToken: function(accessTokenResponse) {
var contentType = accessTokenResponse.getContentType();
var contentBody = accessTokenResponse.getBody();
var paramMap = accessTokenResponse.getparameters();
var params = contentBody.split('&');
var parts;
params.forEach(function(param) {
parts = param.split('=');
paramMap.put(parts[0], parts[1]);
});
// GitHub tokens do not expire, hardcode expiration to something far away
paramMap.put('expires_in', '365246060');
},
type: 'OAuthGitHubHandler'
});
@sharmaritesh
Copy link

Can this be extended to add a header? If not then is there a way I can add a header for OAuth call?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment