oauth-2.0 - 混合网关环境中的 WSO2 始终路由到沙盒 URL,即使与生产访问令牌一起使用也是如此
问题描述
我正在使用 WSO2 APIM 3.0.0 版本,并且我已经使用现有的 swagger 定义在 WSO2 中发布了一个 API。
我正在使用混合网关环境,将“生产”和“沙盒”URL 配置为不同的代码环境(出于测试目的,“生产”URL 会命中我们的 qa 框,而“沙盒”会命中我的本地环境)。我刚刚注意到 WSO2 总是将调用路由到沙盒环境(我的本地),即使我使用“生产”访问令牌也是如此。
除了简单地从 devportal 为 prod 和沙箱生成不同的访问令牌以将其路由到所需的环境之外,我还需要做些什么吗?
这是否意味着我必须始终为不同的环境使用不同的网关?
我使用 OAUTH 和 JWT 令牌类型进行了测试,具有不同的授权机制,它仍然做同样的事情。
根据要求附加 synapse-config:
<?xml version="1.0" encoding="UTF-8"?><api xmlns="http://ws.apache.org/ns/synapse" name="admin--XXXBackendPlatform" context="/WSO2/1.0.0" version="1.0.0" version-type="context">
<resource methods="POST" url-mapping="xxxxx" faultSequence="fault">
<inSequence>
<property name="api.ut.backendRequestTime" expression="get-property('SYSTEM_TIME')"/>
<filter source="$ctx:AM_KEY_TYPE" regex="SANDBOX">
<then>
<send>
<endpoint key="XXXBackendPlatform--v1.0.0_APIsandboxEndpoint"/>
</send>
</then>
<else>
<sequence key="_production_key_error_"/>
</else>
</filter>
</inSequence>
<outSequence>
<class name="org.wso2.carbon.apimgt.gateway.handlers.analytics.APIMgtResponseHandler"/>
<send/>
</outSequence>
</resource>
<handlers>
<handler class="org.wso2.carbon.apimgt.gateway.handlers.common.APIMgtLatencyStatsHandler">
<property name="apiUUID" value="6535a4b7-759b-4f0e-8980-eab80aaee847"/>
</handler>
<handler class="org.wso2.carbon.apimgt.gateway.handlers.security.CORSRequestHandler">
<property name="apiImplementationType" value="ENDPOINT"/>
<property name="AuthorizationHeader" value="WSO2_Auth"/>
</handler>
<handler class="org.wso2.carbon.apimgt.gateway.handlers.security.APIAuthenticationHandler">
<property name="RemoveOAuthHeadersFromOutMessage" value="true"/>
<property name="APILevelPolicy" value="Unlimited"/>
<property name="AuthorizationHeader" value="WSO2_Auth"/>
<property name="CertificateInformation" value="{}"/>
<property name="APISecurity" value="oauth2,oauth_basic_auth_api_key_mandatory"/>
<property name="apiUUID" value="6535a4b7-759b-4f0e-8980-eab80aaee847"/>
</handler>
<handler class="org.wso2.carbon.apimgt.gateway.handlers.throttling.ThrottleHandler"/>
<handler class="org.wso2.carbon.apimgt.gateway.handlers.analytics.APIMgtUsageHandler"/>
<handler class="org.wso2.carbon.apimgt.gateway.handlers.analytics.APIMgtGoogleAnalyticsTrackingHandler">
<property name="configKey" value="gov:/apimgt/statistics/ga-config.xml"/>
</handler>
<handler class="org.wso2.carbon.apimgt.gateway.handlers.ext.APIManagerExtensionHandler"/>
</handlers>
</api>
解决方案
根据以下部分,您只在 API 中配置了一个沙盒端点。如果您使用生产密钥访问 API,您应该会收到错误消息。
<filter source="$ctx:AM_KEY_TYPE" regex="SANDBOX">
<then>
<send>
<endpoint key="XXXBackendPlatform--v1.0.0_APIsandboxEndpoint"/>
</send>
</then>
<else>
<sequence key="_production_key_error_"/>
</else>
</filter>
推荐阅读
- android - 通过 Kotlin DSL 实现的 Android 特定风味依赖
- curl - 浏览器无法下载文件,但 curl 命令可以
- laravel - 获取错误的路线而不是在 laravel 中声明的路线来上传文件
- php - 将基于范围条件的嵌套 if-else 转换为 switch 语句
- vue.js - 如何在数据库 vue.js 项目中存储嵌套对象数据。(哪种格式?)
- java - Mockito when 不是模拟而不是调用实际方法
- c# - Microsoft bot 框架 - Bot 频道注册。无法将录制的视频从 Skype 保存到 Azure 存储帐户
- c# - 使用 ASP Dot net MVC 使用外部 Restful Web API
- linux - 如何从特定行 grep 字符串?
- firebase - 安排 Google Cloud Tasks 调用 Firebase 功能