-
-
Save dzmitry-savitski/0c9c7f54ad8c1c87fad44fa9b28924a7 to your computer and use it in GitHub Desktop.
ig
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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