Hi,
My requirement is to attach OAUTH policy according to content of request payload.
request payload is:
{
"Url" : "abc.xyz.com",
"data" : { }
}
So I have created a javascript and attached with preflow.
my javaScript is as below
var getPayload = context.getVariable('request.content'); print("getPayload::::" +getPayload); var str = context.getVariable("getPayload.Url"); var n = false; if(str !== null){ var n = str.includes("xyz"); } if(n) print("n::::" + n); // I want to call/attach OAUTH policy here else{ print("n::::"+n); // No authentication }
Solved! Go to Solution.
Hi @neha ,
You cannot attach or detach policies using javascript. But, you can achieve the same result using the combination of javascript & policy conditions.
var getPayload = context.getVariable('request.content'); print("getPayload::::" +getPayload); var str = context.getVariable("getPayload.Url"); var n = false; if(str !== null){ var n = str.includes("xyz"); } if(n) context.setVariable("attachOAuth", true); // I want to call/attach OAUTH policy here else{ context.setVariable("attachOAuth", false); print("n::::"+n); // No authentication }
In OAuth Policy step, add condition,
<Step> <Condition>attachOAuth = true</Condition> <Name>OAuth</Name> </Step>
For more info, please refer docs here. Keep us posted if any.
Hi @neha ,
You cannot attach or detach policies using javascript. But, you can achieve the same result using the combination of javascript & policy conditions.
var getPayload = context.getVariable('request.content'); print("getPayload::::" +getPayload); var str = context.getVariable("getPayload.Url"); var n = false; if(str !== null){ var n = str.includes("xyz"); } if(n) context.setVariable("attachOAuth", true); // I want to call/attach OAUTH policy here else{ context.setVariable("attachOAuth", false); print("n::::"+n); // No authentication }
In OAuth Policy step, add condition,
<Step> <Condition>attachOAuth = true</Condition> <Name>OAuth</Name> </Step>
For more info, please refer docs here. Keep us posted if any.
Also, I think you need to do a var jsonPayload = JSON.parse(getPayload) ; var str = jsonPayload.Url; ... since getPayload.Url is not a context variable but just part of the json payload in your example.
User | Count |
---|---|
2 | |
1 | |
1 | |
1 | |
1 |