May 8, 2018 at 11:20 am #21791Nigel ElliottParticipant
I am trying to use the Groovy REST connector to connect to a third party REST API. The third party REST API uses in essence a Bearer token for all REST requests after the initial authentication. So the steps would be:
1. Call /api/authenticate/login (Pass username and password)
2. Response would includes an access token value
3. Call /api/user/ (Pass access token in HTTP Header, i.e, Authentication: Bearer <access token>)
Using the AuthenticateScript.groovy I can get the access token, my issue is what do I do with it in terms of being able to use it in the other scripts, I see two possible solutions:
1. Add a new header the Default HTTP Header which would then be includes in all calls
2. Store the access token somewhere which can be accessed by the other scripts, which can then add the header in the REST call.
Option 1 would be cleaner as it wouldn’t mean having to change each script to add the header.
Happy to entertain any other options you may have.
June 27, 2018 at 4:56 pm #22406gaelParticipant
- This topic was modified 4 years, 3 months ago by Peter Major.
If you manage to get the BearerToken with the Authenticate script, then you can store it in the Configuration propertyBag. It is a concurrent Map shared between connector instances.
In your script you can easily access since the shared configuration object is injected in all scripts
You must be logged in to reply to this topic.