Skip to main content

Groovy Script

import java.lang.String

int start=requestBodyTextFromClient.indexOf("access_token")+16
int end=requestBodyTextFromClient.indexOf("\"",start+1)
String token=requestBodyTextFromClient.substring(start,end)
requestHeaderMapToTargetAPI.put("Authorization", "Bearer " + token)

Explanation

This script performs the following operations:
  1. Finding Token: Finds the access_token field from request body
  2. Extracting Token: Extracts the token value
  3. Adding Header: Adds it to Authorization header as Bearer token
This script should be run on the request line (Request Policy) because it uses the requestBodyTextFromClient and requestHeaderMapToTargetAPI variables.