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

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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
Asked in Jira Service Desk

Calling all Insight users, we need your help!

Hello Insight users,  As part of our (Mindville's) acquisition by Atlassian, our training team is looking to build some new Insight training materials. It would really helpful if you can ...

161 views 1 1
View question

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