Skip to content

Instantly share code, notes, and snippets.

@dzmitry-savitski
Last active June 24, 2025 17:35
Show Gist options
  • Select an option

  • Save dzmitry-savitski/0c9c7f54ad8c1c87fad44fa9b28924a7 to your computer and use it in GitHub Desktop.

Select an option

Save dzmitry-savitski/0c9c7f54ad8c1c87fad44fa9b28924a7 to your computer and use it in GitHub Desktop.
ig
import org.forgerock.http.protocol.Request
import org.forgerock.http.protocol.Response
import org.forgerock.http.protocol.Form
import org.forgerock.http.protocol.UrlEncodedFormEntity
// Build form with credentials
def form = new Form()
form.add("grant_type", "client_credentials")
form.add("client_id", "my-client-id")
form.add("client_secret", "my-client-secret")
form.add("scope", "my-scope")
// Build request
def req = new Request()
req.setMethod("POST")
req.setUri("https://auth.example.com/oauth2/token")
req.getHeaders().add("Content-Type", "application/x-www-form-urlencoded")
req.setEntity(new UrlEncodedFormEntity(form))
// Send the request and handle the response
http.send(req).thenAccept { Response externalResp ->
def status = externalResp.getStatus()
def body = externalResp.getEntity().getString()
logger.info("Token endpoint responded with status $status")
logger.info("Body: $body")
}
return next.handle(context, request)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment