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,466,775
Community Members
 
Community Events
176
Community Groups

Scriptrunner failing to execute confluence query using applink from Jira

Hello,
Im attempting to connect to Confluence from Jira via applink leveraging the provided adaptivist solution at https://library.adaptavist.com/entity/create-a-confluence-page-for-each-subtask-of-an-issue but it is continually failing with a 'nonce_used' error when the cql call is executed.
I've compared the HTTP headers between Jira and confuence for the ouath calls and it all looks like it matches on both sides and at this point Im completely stuck.  I've also tried both applink config options of 'oauth' and 'oauth with impersonation' with the same failing result.


I really need to get this solutoin working since making rest calls using basic auth or an access token is a non-starter due to then needing to add the auth details in the script.

Can someone please help me to understand what may be going wrong here?

  • Jira Server: 8.5.3
  • Confluence Server: 7.5.2
  • Scriptrunner: 6.23

Code being executed from Scriptrunner console:

findConfluencePages()

static ApplicationLink createPrimaryConfluenceLink() {
def applicationLinkService = ComponentLocator.getComponent(ApplicationLinkService)

final def conflLink = applicationLinkService.getPrimaryApplicationLink(ConfluenceApplicationType.class)
conflLink
}

int findConfluencePages() {


def confluenceLink = createPrimaryConfluenceLink()
assert confluenceLink // must have a working app link set up

def authenticatedRequestFactory = confluenceLink.createImpersonatingAuthenticatedRequestFactory()


def responseBody
authenticatedRequestFactory
.createRequest(Request.MethodType.GET, "cql=type%3Dpage%20and%20space%3DAE%20and%20label%3D%22rsp-unreleased%22&expand=body")
.addHeader("Content-Type", "application/json")
.execute(new ResponseHandler<Response>() {
@Override
void handle(Response response) throws ResponseException {
if (response.statusCode != HttpURLConnection.HTTP_OK) {
throw new Exception(response.responseBodyAsString)
} else {
responseBody = new JsonSlurper().parseText(response.responseBodyAsString)
}
}
})

responseBody["id"] as Integer
}



 

Failing stack:

java.lang.Exception: oauth_problem=nonce_used at Script1167$1.handle(Script1167.groovy:44) at com.atlassian.applinks.oauth.auth.OAuthResponseHandler.handle(OAuthResponseHandler.java:48) at com.atlassian.plugins.rest.module.jersey.JerseyRequest$1.handle(JerseyRequest.java:115) at com.atlassian.plugins.rest.module.jersey.JerseyRequest$1.handle(JerseyRequest.java:113) at com.atlassian.plugins.rest.module.jersey.JerseyRequest$2.handle(JerseyRequest.java:134) at com.atlassian.sal.core.net.HttpClientRequest.executeAndReturn(HttpClientRequest.java:102) at com.atlassian.plugins.rest.module.jersey.JerseyRequest.executeAndReturn(JerseyRequest.java:131) at com.atlassian.plugins.rest.module.jersey.JerseyRequest.execute(JerseyRequest.java:113) at com.atlassian.applinks.core.auth.ApplicationLinkRequestAdaptor.execute(ApplicationLinkRequestAdaptor.java:50) at com.atlassian.applinks.oauth.auth.OAuthResponseHandler.handle(OAuthResponseHandler.java:46) at com.atlassian.plugins.rest.module.jersey.JerseyRequest$1.handle(JerseyRequest.java:115) at com.atlassian.plugins.rest.module.jersey.JerseyRequest$1.handle(JerseyRequest.java:113) at com.atlassian.plugins.rest.module.jersey.JerseyRequest$2.handle(JerseyRequest.java:134) at com.atlassian.sal.core.net.HttpClientRequest.executeAndReturn(HttpClientRequest.java:102) at com.atlassian.plugins.rest.module.jersey.JerseyRequest.executeAndReturn(JerseyRequest.java:131) at com.atlassian.plugins.rest.module.jersey.JerseyRequest.execute(JerseyRequest.java:113) at com.atlassian.applinks.core.auth.ApplicationLinkRequestAdaptor.execute(ApplicationLinkRequestAdaptor.java:50) at com.atlassian.applinks.oauth.auth.OAuthRequest.execute(OAuthRequest.java:71) at com.atlassian.sal.api.net.Request$execute$0.call(Unknown Source) at Script1167.findConfluencePages(Script1167.groovy:40) at Script1167.run(Script1167.groovy:15)

1 answer

@Greg Bailey 

can you try method may it will help you

 

def authenticatedRequestFactory = confluenceLink.createAuthenticatedRequestFactory()

def req = authenticatedRequestFactory.createRequest(GET,"cql=type%3Dpage%20and%20space%3DAE%20and%20label%3D%22rsp-unreleased%22&expand=body")

def handler = new ApplicationLinkResponseHandler<Map>() {
@Override
Map credentialsRequired(Response response) throws ResponseException {
return null
}

@Override
Map handle(Response response) throws ResponseException {
assert response.statusCode == 200
new JsonSlurper().parseText(response.getResponseBodyAsString()) as Map
}
}

def sessionDetails = req.execute(handler)
log.warn("Making the request as: " + sessionDetails)
def json_str = JsonOutput.toJson(sessionDetails)
def jsonSlurper = new JsonSlurper()
def cfg = jsonSlurper.parseText(json_str)
assert cfg instanceof Map
def id = cfg.results['id']

return id

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events