This topic has 1 reply, 2 voices, and was last updated 4 years, 1 month ago by gael.

  • Author
  • #21791
     Nigel Elliott

    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.

    Many Thanks.

    • 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

    configuration.getPropertyBag().put(“token”, “xyz”)

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.

©2022 ForgeRock - we provide an identity and access platform to secure every online relationship for the enterprise market, educational sector and even entire countries. Click to view our privacy policy and terms of use.

Log in with your credentials

Forgot your details?