WSO2-Api Manager-将Post Body参数作为URL查询字符串传递给Moodle

涡流

我们正在实施WSO2-AM,以处理希望从Internet公开的Moodle LMS对某些内部API的访问。

我正在配置通过WSO2对此LMS的访问权限,但是遇到了无法解决的问题。

我意识到WSO2文档非常丰富,但是我实际上无法找到此配置的特定实例。

背景: Moodle本身以非常不标准的方式实现了其API。他们称它们为REST,但并不是真正的宁静。某些参数(例如,用户令牌)在URL查询字符串中传递,而不是使用查询主体中的标头。

首先,我在WSO2中配置了两个API,一个用于向Moodle请求用户令牌(Moodle要求此权限以允许特定用户访问该API),另一个用于获取用户注册的课程列表。

通过WSO2从Moodle获取用户令牌的第一个请求按预期进行。我按您期望的那样通过标头传递了用户名/密码/服务参数(以便通过HTTPS对其进行加密)传递给WSO2,并将其作为POST推送到Moodle。Moodle通过WSO2做出的响应符合预期,这是一个JSON有效负载,其中包含令牌,我的客户端随后对该令牌进行解析以在后续请求中使用。

然后,下一个请求是在Moodle中调用更有用的服务,以使用户注册课程。这里有两个我不确定如何解决的问题。

问题: Moodle希望对Web服务的调用使用GET或POST参数。当我使用方便测试的GET时,从客户端传递到WSO2的参数要么是错误的(对于“ userid”而言),要么是丢失的(对于wstoken字段而言,该信息在帖子中)身体)。

在API发布者中,我将WSO2中的API配置为POST,URL模式为{version} / courses / {userid},API定义如下: API定义

API端点配置为: API端点配置

网址:http://(moodleurl)/webservice/rest/server.php?wstoken= {uri.var.wstoken}&wsfunction = core_enrol_get_users_courses&moodlewsrestformat = json&userid = {uri.var.userid}

GET URL as received by Apache hosting Moodle is: xx.xx.xx.xx - - [09/Aug/2016:10:36:03 +0930] "POST /webservice/rest/server.php?wstoken=&wsfunction=core_enrol_get_users_courses&moodlewsrestformat=json&userid=6/6 HTTP/1.1" 200 270

So, the two issues are the missing 'wstoken' parameter (which is in the post body provided to WSO2, and the 'userid' being doubled up with a slash between the items.

I have run the client via a proxy and the data appears to be sent correctly to WSO2: 客户端-> WSO2代理

So I'm wondering what I can do about these problems:

Is there a different URL parameter I can use to correctly include a posted body param in the URL out to the service API address?

Is there some specific configuration problem I've made that's causing the userid parameter to break in this manner?

The posted parameters from the client do appear to be included in the post to Moodle by WSO2; so it is likely they can be stripped from the URL and simply included in the post body to Moodle by WSO2, meaning that it's likely only the issue with the userid parameter that needs to be resolved to allow this to work - unfortunately I'm not sure how to place a proxy between WSO2 and Moodle itself to validate the parameters that are posted to the API, short of using Wireshark.

Isuru Wijesinghe

The 'userid' being doubled up with a slash between the items because the URI template of the API's resource is automatically appended to the end of the HTTP endpoint at runtime. For an example in your case you defined the endpoint url as:

http://(moodleurl)/webservice/rest/server.php?wstoken={uri.var.wstoken}&wsfunction=core_enrol_get_users_courses&moodlewsrestformat=json&userid={uri.var.userid} 

Then url pattern (/{userid}) appends to the endpoint url by default. To overcome this issue you can use the following mediator setting to remove the URL postfix from the backend endpoint:

<property name="REST_URL_POSTFIX" scope="axis2" action="remove"/>

For more on this please refer the link given in [1].

You can read the variables in the resources (urls) during mediation runtime using property values with the "uri.var." prefix. For example, in your case HTTP endpoint gets the wstoken and userid as the uri variables. But wstoken contains in the body section of the request. Therefore you cannot add it by introducing wstoken={uri.var.wstoken} as a query paramter to the endpoint. One way that you can overcome this issue is by defining wstoken as a query parameter by changing the parameter Type to query. The other way is you can define it in the header of the incoming request.

[1]。https://docs.wso2.com/display/AM190/Map+the+Parameters+of+your+Backend+URLs+with+the+API+Publisher+URLs

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

WSO2 Api Manager:如何查看请求的 URL

来自分类Dev

wso2 API Manager API 丢失

来自分类Dev

WSO2 API Manager CPU图形

来自分类Dev

将 WSO2 API Manager 迁移到 2.1.0 后未显示 API

来自分类常见问题

WSO2 API Manager异步API支持

来自分类Dev

WSO2 API Manager API身份验证失败

来自分类Dev

WSO2 API Manager 3.0.0中的API存储

来自分类Dev

WSO2 API Manager异步API支持

来自分类Dev

WSO2 API Manager - API 特定的配置文件

来自分类Dev

wso2 api manager 如何保护后端api

来自分类Dev

WSO2 Api Manager - 从 SOAP 生成 REST API

来自分类Dev

使用WSO2 Identity Server和WSO2 API Manager保护后端

来自分类Dev

WSO2 API Manager启动时间过长

来自分类Dev

WSO2 API Manager - postgres issue on new install

来自分类Dev

是否可以在Openshift中运行WSO2 Api Manager?

来自分类Dev

WSO2 API Manager-有可用的更新

来自分类Dev

如何使用Github设置WSO2 API Manager登录?

来自分类Dev

关于WSO2 API Manager数据源

来自分类Dev

WSO2 API Manager-有可用的更新

来自分类Dev

WSO2 Api Manager:如何记录服务

来自分类Dev

WSO2 API Manager运行状况检查

来自分类Dev

如何使用Github设置WSO2 API Manager登录?

来自分类Dev

使用cURL测试wso2 Api Manager

来自分类Dev

WSO2 API Manager控制台上的定期错误

来自分类Dev

WSO2 API Manager使用Identity Server存储访问

来自分类Dev

WSO2 api manager 共享应用订阅

来自分类Dev

WSO2 API Manager 中的数据访问配置

来自分类Dev

用于双活部署的 WSO2 API Manager NFS

来自分类Dev

如何将查询字符串参数传递给ASP.NET Web API 2