Last active
          November 18, 2022 19:16 
        
      - 
      
- 
        Save jnerius/0e639c09f7708ef3bdf15f264375dd6c to your computer and use it in GitHub Desktop. 
    ServiceNow OAuth Handler Script Include for processing OAuth Responses from GitHub
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | 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' | |
| }); | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
            
Can this be extended to add a header? If not then is there a way I can add a header for OAuth call?