
var responseJSONstring = context.getVariable("request.content");
var responseJSON = JSON.parse(responseJSONstring);
context.setVariable("request.header.Authorization", "Bearer " + responseJSON.jws);
<!-- This policy can be used to create or modify the standard HTTP request and response messages -->
<AssignMessage async="false" continueOnError="false" enabled="true" xmlns='http://www.sap.com/apimgmt'>
<!-- Sets a new value to the existing parameter -->
<Add>
<Headers>
<Header name="Authorizaton">{request.header.Authorization}</Header>
</Headers>
</Add>
<IgnoreUnresolvedVariables>false</IgnoreUnresolvedVariables>
<AssignTo createNew="false" type="response">response</AssignTo>
</AssignMessage>
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<LookupCache async="false" continueOnError="false" enabled="true" xmlns="http://www.sap.com/apimgmt">
<CacheKey>
<KeyFragment>JWT_KEYS</KeyFragment>
</CacheKey>
<Scope>Global</Scope>
<AssignTo>JWTKeys.content</AssignTo>
</LookupCache>
<ServiceCallout async="true" continueOnError="false" enabled="true" xmlns="http://www.sap.com/apimgmt">
<Response>JWTKeys</Response>
<Timeout>60000</Timeout>
<HTTPTargetConnection>
<URL>https://accounts.eu1.gigya.com/accounts.getJWTPublicKey?apiKey=******&V2=true</URL>
</HTTPTargetConnection>
</ServiceCallout>
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<PopulateCache async="false" continueOnError="false" enabled="true" xmlns="http://www.sap.com/apimgmt">
<CacheKey>
<KeyFragment>JWT_KEYS</KeyFragment>
</CacheKey>
<Scope>Global</Scope>
<ExpirySettings>
<TimeoutInSec>86400</TimeoutInSec>
</ExpirySettings>
<Source>JWTKeys.content</Source>
</PopulateCache>
<!-- Verify JWT TOken -->
<VerifyJWT async="false" continueOnError="false" enabled="true" xmlns="http://www.sap.com/apimgmt">
<Algorithm>RS256</Algorithm>
<PublicKey>
<JWKS ref="JWTKeys.content"/>
</PublicKey>
</VerifyJWT>
function formDynamicQuery(nationalID,passportNo){
var query = null;
if(nationalID !== null && nationalID ){
query = "data.nationalID =%27" + nationalID + "%27";
}
else {
query = "data.passport.number =%27" + passportNo + "%27";
}
return query;
}
var responseJSONstring = context.getVariable("jwt.verifyJWT.decoded.claim.data");
var responseJSON = JSON.parse(responseJSONstring);
var profile = responseJSON.params.profile;
var passportNo = null;
var query = null;
if(responseJSON.params.data){
if(responseJSON.params.data.passport){
context.setVariable("passportNo",responseJSON.params.data.passport.number);
passportNo = responseJSON.params.data.passport.number;
context.setVariable("passportExpiryDate",responseJSON.params.data.passport.expiryDate);
}
if(responseJSON.params.data.nationalID){
context.setVariable("nationalID",responseJSON.params.data.nationalID);
}
if(responseJSON.params.data.nationalID || responseJSON.params.data.passportNo){
query = formDynamicQuery(responseJSON.params.data.nationalID,responseJSON.params.data.passportNo);
}
}
context.setVariable("query",query);
<!-- this policy lets you call to an external service from your API flow -->
<ServiceCallout async="false" continueOnError="false" enabled="true" xmlns="http://www.sap.com/apimgmt">
<!-- The request that gets sent from the API proxy flow to the external service -->
<Request/>
<!-- the variable into which the response from the external service should be stored -->
<Response>IDResponse</Response>
<!-- The time in milliseconds that the Service Callout policy will wait for a response from the target before exiting. Default value is 120000 ms -->
<Timeout>30000</Timeout>
<HTTPTargetConnection>
<!-- The URL to the service being called -->
<URL>https://accounts.eu1.gigya.com/accounts.search?apiKey=****&userKey=****&secret=*****&query=select UID from accounts where {query}</URL>
<!-- The SSL reference to be used to access the https url -->
</HTTPTargetConnection>
</ServiceCallout>
function checkRecordExists(response){
if(response != null ){
if(response.results && response.results.length > 0){
return true;
}
}
return false;
}
var response = context.getVariable("IDResponse.content");
var parseData = JSON.parse(response);
var count = parseData.totalCount;
var nationalID = context.getVariable("nationalID");
var passportNo = context.getVariable("passportNo");
var ret = {status : "OK"};
if(count > 0){
if(nationalID && nationalID !== null){
var fieldName = "data.nationalID";
var message = "Sorry, We are unable to process your request for registration as the user with same National ID already exists. Please contact Customer Care Center";
}
if(passportNo && passportNo !== null){
var fieldName = "data.passport.number";
var message = "Sorry, We are unable to process your request for registration as the user with same Passport Number already exists. Please contact Customer Care Center";
}
ret.status = "FAIL";
ret.data= {
validationErrors : [
{
fieldName: fieldName,
message: message
}
]
}
}
context.setVariable("status",ret.status);
context.setVariable("idresp",JSON.stringify(ret));
context.setVariable("Count",count);
<!-- This policy can be used to create or modify the standard HTTP request and response messages -->
<AssignMessage async="false" continueOnError="false" enabled="true" xmlns='http://www.sap.com/apimgmt'>
<!-- Sets a new value to the existing parameter -->
<Set>
<Payload contentType="application/json; charset=utf-8" variablePrefix="@" variableSuffix="#">@idresp#</Payload>
<StatusCode>200</StatusCode>
<ReasonPhrase>Invalid ID</ReasonPhrase>
</Set>
<IgnoreUnresolvedVariables>false</IgnoreUnresolvedVariables>
<AssignTo createNew="false" type="response">response</AssignTo>
</AssignMessage>
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
3 | |
3 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 |