【问题标题】:WSO2 APIM 2.0 Is it possible to customize or redirect to the /token urlWSO2 APIM 2.0 是否可以自定义或重定向到 /token url
【发布时间】:2017-05-04 07:38:03
【问题描述】:

我正在将我的 API 从旧系统迁移到 WSO2 APIM 2.0.0,并试图让我的 API 用户能够透明地切换。我已经迁移了我现有的 consumer_key/secrets。

是否可以将 /token API 自定义为其他东西?

在我的旧系统中,OAuth 令牌通过类似的路径进行管理 /oauth/client_credential/accesstoken

也许可以将 /oauth/client_credential/accesstoken 映射到 /token 以便两者都可以使用?

【问题讨论】:

    标签: oauth wso2 wso2-am wso2carbon


    【解决方案1】:

    如果你只是想改变 /token api 的基本路径,你可以在 api manager 前面使用一些反向代理(例如 nginx),或者在 api manager 本身内部创建一个这样的代理 api。

    <api xmlns="http://ws.apache.org/ns/synapse" name="_WSO2AMTokenAPIProxy_" context="/oauth/client_credential/accesstoken">
        <resource methods="POST" url-mapping="/*" faultSequence="_token_fault_">
            <inSequence>
            <property name="uri.var.portnum" expression="get-property('https.nio.port')"/>
                <send>
                    <endpoint>
                         <http uri-template="https://localhost:{uri.var.portnum}/token">
                            <timeout>
                                <duration>60000</duration>
                                <responseAction>fault</responseAction>
                            </timeout>
                        </http>
                    </endpoint>
                </send>
            </inSequence>
            <outSequence>
                <send/>
            </outSequence>
        </resource>
        <handlers/>
    </api>
    

    您需要将此复制到&lt;APIM_HOME&gt;/repository/deployment/server/synapse-configs/default/api/_WSO2AMTokenAPIProxy_.xml

    【讨论】:

    • 感谢@Bhathiya,当我使用它时,我遇到了与未评估 uri.var.portnum 相关的错误。我对 localhost:8280 进行了硬编码,但随后我收到了与 CSRF attach 相关的警告,被阻止了.....
    【解决方案2】:

    Bhathiya 建议的解决方案有效,只需调整代理端点

    <api xmlns="http://ws.apache.org/ns/synapse" name="_WSO2AMTokenAPIProxy_" context="/oauth/client_credential/accesstoken">
    <resource methods="POST" url-mapping="/*" faultSequence="_token_fault_">
        <inSequence>
            <send>
                <endpoint>
                     <http uri-template="http://127.0.0.1:8280/token">
                        <timeout>
                            <duration>60000</duration>
                            <responseAction>fault</responseAction>
                        </timeout>
                    </http>
                </endpoint>
            </send>
        </inSequence>
        <outSequence>
            <send/>
        </outSequence>
    </resource>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-30
      • 1970-01-01
      • 2012-09-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-22
      相关资源
      最近更新 更多