Missed Team ’24? Catch up on announcements here.

×
Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

ScriptRunner - authentication inside REST endpoint

fjodors
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 13, 2018

Hello

I'd like to create authentication inside my ScriptRunner Endpoint.

I've created a Script Runner REST endpoint that returns some data from my Jira instance and I'd like to access this data from other application (PowerBI)

The problem is that I am unable to configure authentication in my REST Endpoint.
Since I am able to pass from PowerBI application basic authentication parameters, I assume I should handle passed credentials in my Rest Endpoint function.

I 've reviewed some examples and tried to create authentication using code below, however it returns me an error "MissingMethodException"
Could you help me to understand what is wrong?

 

My code:

import com.onresolve.scriptrunner.runner.rest.common.CustomEndpointDelegate
import javax.ws.rs.core.MediaType
import groovyx.net.http.HTTPBuilder
import org.apache.http.HttpRequestInterceptor;
import org.apache.http.HttpRequest;
import org.apache.http.protocol.HttpContext;
import groovy.json.JsonSlurper;
import groovy.json.JsonBuilder;
import groovyx.net.http.Method;
import static groovyx.net.http.Method.*
import groovyx.net.http.ContentType
import groovy.transform.BaseScript
import javax.ws.rs.core.MultivaluedMap
import javax.ws.rs.core.Response

@BaseScript CustomEndpointDelegate delegate
    
    
    
AuthTest(httpMethod: "GET") { MultivaluedMap queryParams ->
    def JIRA_REST_URL = "https://<myJiraServer>"
    def JIRA_API_URL = JIRA_REST_URL + "/rest/auth/1/session"
    def http = new HTTPBuilder(JIRA_API_URL);
    def rt ='';
    def abc ='abcdefg one';
    
    
    http.request(Method.POST, ContentType.JSON) { resp, JSON ->
        //myname and mypass I will receive from PowerBi
        def body =  [username: 'myname', password: 'mypass']
            rt = JSON            
    }
    //if request is OK, do something
    
    Response.ok().type(MediaType.TEXT_HTML).entity(abc.toString()).build()
}

 

Error:

2018-03-13 11:42:20,635 ERROR [common.UserCustomScriptEndpoint]: Script endpoint failed on method: GET AuthTest
groovy.lang.MissingMethodException: No signature of method: Script2013$_run_closure1$_closure2.doCall() is applicable for argument types: (org.apache.http.client.methods.HttpPost) values: [POST https://<myJiraServer>/rest/auth/1/session HTTP/1.1]
Possible solutions: doCall(java.lang.Object, java.lang.Object), findAll(), findAll(), isCase(java.lang.Object), isCase(java.lang.Object)    

 

Thank you in advance!

 

Fyodor

 

 

 

0 answers

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events