signpost/exception/OAuthException when trying to use Oauth10 on external API request on ScriptRunner
Asked by Carlos Barrera:

I'm developing an integration of some external system (NetSuite) with our Jira Instance, and I am trying to trigger a call to an already developed and working Restlet (verified auth and access via Postman) by running an script in the Console in ScriptRunner.

While having some trouble finding the way to sign the get request having all the access secret/token and consumer secret/token, I ended up finding the right way:

```
def client = new RESTClient(hostUrl)
client.auth.oauth(consumerKey, consumerSecret, accessToken, tokenSecret)

```

I checked by running this approach as independent groovy script in intellij and it correctly compiles and send the request (although I need to handle how to configure it to use HMAC-SHA256 instead of HMAC-SHA1, but that's another story)

But when I run the code in the ScriptRunner console it complains with oauth exception

```
Something went wrong: NoClassDefFoundError

oauth/signpost/OAuthConsumer


```

So is the Oauth signing of requests not supported? Is there anything extra I need to do to be able to make it happen?

Thanks

PS: Any way to add the Realm parameter to the Oauth auth header?


Answers:
author: Carlos Barrera
body: Sorry, confused the field to respond


author: Ram Kumar Aravindakshan _Adaptavist_
body: Hi [@Carlos Barrera](/t5/user/viewprofilepage/user-id/8579)

Please clarify what object types have you used for cosumerKey, consumerSecret, accessToken and tokenSecret parameters?

Are you using all String values?

Also, please clarify what version of Jira and ScriptRunner you are using when performing this test.

Thank you and Kind regards,  
Ram

comments: author: Carlos Barrera
body: HI [@Ram Kumar Aravindakshan _Adaptavist_](https://community.atlassian.com/t5/user/viewprofilepage/user-id/2988015) ,

Sure, the object types are:

```
String consumerKey = "CONSUMER_KEY"
String consumerSecret = "CONSUMER_SECRET"
String accessToken = "ACCESS_TOKEN"
String tokenSecret = "TOKEN_SECRET"
```

And the jira and scriptrunner versions are:

```
Scriptrunner version
8.28.30508561

Jira version
v9.12.8
```

Thanks :)


author: Carlos Barrera
body: Hi [@Ram Kumar Aravindakshan _Adaptavist_](/t5/user/viewprofilepage/user-id/2988015) ,

Providing example simple code where I can Replicate the error:  

```
import groovyx.net.http.ContentType

import groovyx.net.http.HttpResponseDecorator

import groovyx.net.http.RESTClient

// Define your OAuth consumer credentials

import static Constants.*

class Constants {

static final String ACCOUNT_ID = "ACCOUNT_ID";

static final String CONSUMER_KEY = "CONSUMER_KEY";

static final String CONSUMER_SECRET = "CONSUMER_SECRET";

static final String TOKEN_ID = "TOKEN_ID";

static final String TOKEN_SECRET = "TOKEN_SECRET";

}

final String RESTLET_DOMAIN = Constants.ACCOUNT_ID + ".restlets.api.netsuite.com";

final String RESTLET_PATH = "/app/site/hosting/restlet.nl";

final String SCRIPT = "script";

final String DEPLOY = "deploy";

final String RECORD_ID = "recordId";

final String RECORD_TYPE = "recordType";

final externalUrl = "https://$RESTLET_DOMAIN"

final emptyBodyString = '{"dataIn":[]}'

def getResponse = get(externalUrl, RESTLET_PATH, "script=8&deploy=1&recordId=3004&recordType=issue")

if (getResponse) {

def responseGetMap = getResponse as Map

}

def get(def hostUrl, def endpoint, def query) {

 log.warn(hostUrl)

 log.warn(endpoint)

 log.warn(query)

// If authentication mechanism of the API is token-based, it can be specified into this variable

if (hostUrl.toString().contains('&') || hostUrl.toString().contains('?')) {

 log.error 'The parameters of the endpoint must be included in the query variable'

return

 }

def realm = Constants.ACCOUNT_ID

def client = new RESTClient(hostUrl)

 client.auth.oauth(Constants.CONSUMER_KEY, Constants.CONSUMER_SECRET, Constants.TOKEN_ID, Constants.TOKEN_SECRET)

 client.setHeaders([

'Accept' : ContentType.JSON,

 ])

 client.handler.success = { HttpResponseDecorator response, json ->

 json

 }

 client.handler.failure = { HttpResponseDecorator response ->

// Failure can be handled here

 log.error response.entity.content.text

 [:]

 }

 client.get(

 path: endpoint,

 queryString: query,

 contentType: ContentType.JSON

 )

}
```

With this script copy pasted into scriptRunner console, I am able to replicate the error message complaining about the "client.auth.oauth(Constants.CONSUMER_KEY, Constants.CONSUMER_SECRET, Constants.TOKEN_ID, Constants.TOKEN_SECRET)" line

Hope it helps to find the root cause.


author: Ram Kumar Aravindakshan _Adaptavist_
body: HI [@Carlos Barrera](/t5/user/viewprofilepage/user-id/8579)

Could you please share a screenshot of your configuration?

If you are trying to run this via the REST Endpoint, there appears to be an error in your code.

Thank you and Kind regards,  
Ram


author: Carlos Barrera
body: Hi [@Ram Kumar Aravindakshan _Adaptavist_](/t5/user/viewprofilepage/user-id/2988015) ,

I am trying to execute it in the scriptrunner console

![Screenshot 2024-07-02 at 08.20.57.png](https://community.atlassian.com/t5/image/serverpage/image-id/332936i4DA476253A675BDD/image-size/large?v=v2&px=999 "Screenshot 2024-07-02 at 08.20.57.png")

The final goal is to be able to sent post/put request signed with oauth 1.0 authentication against a NetSuite restlet, but first I need to ensure it is working in the script console.

Any specific areas you need a screenshot of?


author: Ram Kumar Aravindakshan _Adaptavist_
body: Hi [@Carlos Barrera](/t5/user/viewprofilepage/user-id/8579)

If you intend to do this via the ScriptRunner console, you do not need to create a class file.

After reviewing your code, it appears that you are trying to connect to an external REST Service.

I suggest using this [Adaptavist Library](https://library.adaptavist.com/entity/use-external-api) example as it provides a pretty straightforward approach to do this.

I hope this helps to resolve your problem.

Thank you and Kind regards,

Ram


author: Carlos Barrera
body: Hi [@Ram Kumar Aravindakshan _Adaptavist_](/t5/user/viewprofilepage/user-id/2988015) ,

That specific script is the example I started with, focusing on the get method, and I can do that when not signing with oauth the requests, but when I try to use the

```
client.auth.oauth(Constants.CONSUMER_KEY, Constants.CONSUMER_SECRET, Constants.TOKEN_ID, Constants.TOKEN_SECRET)
```

part, it suddenly starts complaining about the

```
Something went wrong: NoClassDefFoundError

oauth/signpost/OAuthConsumer
```

Which according to the rest client link in the example page (<https://github.com/jgritman/httpbuilder/wiki/RESTClient>) it is supported as stated in the authentication part of the wiki

<https://github.com/jgritman/httpbuilder/wiki/Authentication>

Is there anything else I need to do to be able to sign my requests with Oauth 1.0 providing the consumer key, consumer secret, token Id and token secret?

You can check that the code is working as expected by changing the url/query to a public one and commenting out the oauth signature line. Then it correctly sends the request, and receives the response. My blocking step now is that whenever I try to enable the Oauth 1.0 signature as stated in the documentation, it starts complaining about this class missing.

Thanks


Tags: adaptavist

data-center

jira-data-center

rest-api

scriptrunner