Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,293,244
Community Members
 
Community Events
165
Community Groups

ScriptRunner - authentication inside REST endpoint

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
Community showcase
Posted in Jira Service Management

Jira Service Management Documentation Opportunities

Hello everyone, Hope everyone is safe! A few months ago we posted an article sharing all the new articles and documentation that we, the AMER Jira Service Management team created. As mentioned ...

147 views 0 3
Join discussion

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you