Copying Value Coming in Body to Header Field
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:
- Finding Token: Finds the
access_tokenfield from request body - Extracting Token: Extracts the token value
- Adding Header: Adds it to Authorization header as Bearer token
not
This script should be run on the request line (Request Policy) because it uses the requestBodyTextFromClient and requestHeaderMapToTargetAPI variables.