Notifications

155 views

Description

Below is a sample code to access REST end point with JWT Bearer grant type Authorization

Instructions

Set up jwt_provider record . After configuration is successful , below code can be executed to access REST end point with JWT Bearer grant type Authorization

var tokenRequest = new sn_auth.GlideOAuthClientRequest();
tokenRequest.setGrantType("urn:ietf:params:oauth:grant-type:jwt-bearer");
tokenRequest.setRequestor("someone@someemail.com");

var oAuthClient = new sn_auth.GlideOAuthClient();
// box_demo is the name of jwt_provider
var tokenResponse = oAuthClient.requestTokenByRequest("box_demo", tokenRequest);
gs.info("Error:" + tokenResponse.getErrorMessage());
var token = tokenResponse.getToken();



if(token) {
gs.info("AccessToken:" + token.getAccessToken());
gs.info("AccessTokenExpiresIn:" + token.getExpiresIn());
// Making a REST call
var restMessage = new sn_ws.RESTMessageV2();
//set the token obtained from above
restMessage.setRequestHeader('Authorization', 'Bearer ' + token.getAccessToken());
restMessage.setHttpMethod("get");
// set end point
restMessage.setEndpoint("https://api.box.com/2.0/folders/109476179807");

var response = restMessage.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
gs.log(responseBody);
}




Article Information

Last Updated:2020-05-07 11:54:32
Published:2020-05-07