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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

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,455,284
Community Members
 
Community Events
175
Community Groups

ScriptRunner - authentication inside REST endpoint

fjodors Rising Star Mar 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

Atlassian Community Events