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?
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
HI @Ram Kumar Aravindakshan _Adaptavist_ ,
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 :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Ram Kumar Aravindakshan _Adaptavist_ ,
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Ram Kumar Aravindakshan _Adaptavist_ ,
I am trying to execute it in the scriptrunner console
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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 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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Ram Kumar Aravindakshan _Adaptavist_ ,
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.