How to enable token based authentication for scripted rest method

vishnukelam
Tera Contributor

Hello Everyone,

 

I am trying to figure out how i can enable token based authentication for scripted rest method. We already have the below scripted rest resource in use and we are trying to add token based authentication. Can someone please guide me through the process. 

 

Oauth is not supported by the third party, they only have option to send auth data as token via URL. Please suggest a way how to enable the Token based authentication for inbound scripted Rest resource.

 

 

 

(function process( /*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {

//todo

// #1 : identify the type of task
gs.info("webhooks" + JSON.stringify(request.body.data));
var Error = new sn_ws_err.ServiceError();
var payload = request.body.data;
// If there's no payload return an error.
if (global.JSUtil.isEmpty(payload))
return new sn_ws_err.BadRequestError("Payload is empty");
try {

if (request.body.data || request.body.data.fields || request.body.data.fields.issuetype.name) {
var pro = true;
var taskType = request.body.data.fields.issuetype.name;
if (taskType == "Initiative") {
pro = new global.MnAJiraDataImport().updateMAProject(request.body.data);
} else if (taskType == "Epic") {
pro = new global.MnAJiraDataImport().updateMAIssue(request.body.data);
} else if (taskType == "Story") {
pro = new global.MnAJiraDataImport().updateMATask(request.body.data);
}
if (pro == true) {
response.setStatus(200);
} else {
Error.setStatus(500);
Error.setMessage('Internal Server Errror');
Error.setDetail('Unable to Process the request ');
return Error;
}
}
} catch (ex) {
Error.setStatus(500);
Error.setMessage('Internal Server Errror');
Error.setDetail('Unable to Process the request ' + ex.toString());
return Error;
}
})(request, response);

 

 

 

 

Thanks in advance

4 REPLIES 4

Allen Andreas
Administrator
Administrator

Hello,

To clarify, do you mean an inbound web services request to your instance and so you want the client sending the request to use an access token (so OAuth)?


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

@Allen Andreas  Yes it is an inbound web services request. Oauth is not supported by the third party, they only have option to send auth data as token via URL.

Please suggest how i can enable the Token based authetication for this inbound.

Hi there, I have a very similar situation.  Were you ever able to get this figured out?