Last active
March 13, 2020 03:17
-
-
Save menakaj/8a20efd7b491fd09718882f6181a2c3d to your computer and use it in GitHub Desktop.
Sequence for access token generation
This file contains 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
<?xml version="1.0" encoding="UTF-8"?> | |
<sequence name="simple-token-gen" trace="disable" xmlns="http://ws.apache.org/ns/synapse"> | |
<property description="access_token" expression="get-property('registry', 'gov:/pizzaOrderingAPI/access_Token')" name="access_token" scope="default" type="STRING"/> | |
<property description="generated_time" expression="get-property('registry','gov:/pizzaOrderingAPI/generated_Time')" name="generated-time" scope="default" type="LONG"/> | |
<property description="client_credentials" name="app-client-auth" scope="default" type="STRING" value="eDU1YVdaWV9iVUJtTXY4U3IzOXJMbWdTSmZBYTpOcGNKdUdFM1JQcldlY3NQQ0wwQ2htd2xucmNh"/> | |
<property expression="json-eval($)" name="message-body" scope="default" type="STRING"/> | |
<property expression="get-property('axis2','REST_URL_POSTFIX')" name="resource" scope="default" type="STRING"/> | |
<filter description="" xpath="get-property('SYSTEM_TIME') - get-property('generated-time') > 3600000 or get-property('access_token') = ''"> | |
<then> | |
<payloadFactory media-type="xml"> | |
<format> | |
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"> | |
<soapenv:Body> | |
<root xmlns=""> | |
<grant_type>client_credentials</grant_type> | |
</root> | |
</soapenv:Body> | |
</soapenv:Envelope> | |
</format> | |
<args/> | |
</payloadFactory> | |
<header expression="fn:concat('Basic ', get-property('app-client-auth'))" name="Authorization" scope="transport"/> | |
<header name="Content-Type" scope="transport" value="application/x-www-form-urlencoded"/> | |
<property description="messageType" name="messageType" scope="axis2" type="STRING" value="application/x-www-form-urlencoded"/> | |
<property description="REST_URL_POSTFIx" name="REST_URL_POSTFIX" scope="axis2" type="STRING" value=""/> | |
<call blocking="true"> | |
<endpoint name="token"> | |
<http method="post" uri-template="https://localhost:8243/token"/> | |
</endpoint> | |
</call> | |
<property expression="get-property('resource')" name="REST_URL_POSTFIX" scope="axis2" type="STRING"/> | |
<property description="generated Time Setter" expression="get-property('SYSTEM_TIME')" name="gov:/pizzaOrderingAPI/generated_Time" scope="registry" type="LONG"/> | |
<property description="generated_token" expression="json-eval($.access_token)" name="generated-access-token" scope="default" type="STRING"/> | |
<property description="new Token setter" expression="get-property('generated-access-token')" name="gov:/pizzaOrderingAPI/access_Token" scope="registry" type="STRING"/> | |
<header expression="fn:concat('Bearer ', get-property('generated-access-token'))" name="Authorization" scope="transport"/> | |
<payloadFactory media-type="json"> | |
<format> | |
$1 | |
</format> | |
<args> | |
<arg evaluator="xml" expression="get-property('message-body')"/> | |
</args> | |
</payloadFactory> | |
</then> | |
<else> | |
<header expression="fn:concat('Bearer ', get-property('access_token'))" name="Authorization" scope="transport"/> | |
</else> | |
</filter> | |
</sequence> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment