<?xml version="1.0" encoding="UTF-8"?>
<!--
  ~  Copyright (c) 2020, WSO2 Inc. (http://wso2.com) All Rights Reserved.
  ~
  ~  WSO2 Inc. licenses this file to you under the Apache License,
  ~  Version 2.0 (the "License"); you may not use this file except
  ~  in compliance with the License.
  ~  You may obtain a copy of the License at
  ~
  ~    http://www.apache.org/licenses/LICENSE-2.0
  ~
  ~  Unless required by applicable law or agreed to in writing,
  ~  software distributed under the License is distributed on an
  ~  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  ~  KIND, either express or implied.  See the License for the
  ~  specific language governing permissions and limitations
  ~  under the License.
  ~
  -->
<!-- OAuth2.0 configured HTTP endpoints -->
<definitions xmlns="http://ws.apache.org/ns/synapse">
    <api name="FoodAPI" context="/foodapi">
        <resource uri-template="/list/{val1}" methods="GET">
            <inSequence>
                <property name="uri.var.val1" expression="get-property('uri.var.val1')"/>
                <switch source="get-property('uri.var.val1')">
                    <case regex="invalidCredentials">
                        <send>
                            <endpoint>
                                <http method="get" uri-template="http://localhost:9000/foodservice/food">
                                    <authentication>
                                        <oauth>
                                            <clientCredentials>
                                                <clientId>my_client_id</clientId>
                                                <clientSecret>my_secret</clientSecret>
                                                <tokenUrl>http://localhost:9000/foodservice/token</tokenUrl>
                                            </clientCredentials>
                                        </oauth>
                                    </authentication>
                                </http>
                            </endpoint>
                        </send>
                    </case>
                    <case regex="oauthServerFailed">
                        <send>
                            <endpoint>
                                <http method="get" uri-template="http://localhost:9000/foodservice/food">
                                    <authentication>
                                        <oauth>
                                            <clientCredentials>
                                                <clientId>my_client_id</clientId>
                                                <clientSecret>my_client_secret</clientSecret>
                                                <tokenUrl>http://localhost:9898/foodservice/token</tokenUrl>
                                            </clientCredentials>
                                        </oauth>
                                    </authentication>
                                </http>
                            </endpoint>
                        </send>
                    </case>
                    <case regex="refreshTokenGrant">
                        <send>
                            <endpoint>
                                <http method="get" uri-template="http://localhost:9000/foodservice/food">
                                    <authentication>
                                        <oauth>
                                            <authorizationCode>
                                                <clientId>my_client_id</clientId>
                                                <clientSecret>my_client_secret</clientSecret>
                                                <refreshToken>wxyz#9876</refreshToken>
                                                <tokenUrl>http://localhost:9000/foodservice/token</tokenUrl>
                                            </authorizationCode>
                                        </oauth>
                                    </authentication>
                                </http>
                            </endpoint>
                        </send>
                    </case>
                    <default>
                        <send>
                            <endpoint>
                                <http method="get" uri-template="http://localhost:9000/foodservice/{uri.var.val1}">
                                    <authentication>
                                        <oauth>
                                            <clientCredentials>
                                                <clientId>my_client_id</clientId>
                                                <clientSecret>my_client_secret</clientSecret>
                                                <tokenUrl>http://localhost:9000/foodservice/token</tokenUrl>
                                            </clientCredentials>
                                        </oauth>
                                    </authentication>
                                </http>
                            </endpoint>
                        </send>
                    </default>
                </switch>
            </inSequence>
            <outSequence>
                <send/>
            </outSequence>
        </resource>
    </api>
</definitions>
