使用REST API检索所有应用程序列表时获取错误502 [英] Getting error 502 when using REST API to retrieves list of all applications
问题描述
GET / imfpush / v1 / apps HTTP / 1.1
主持人:mobilefoundation-3b-mf-server.mybluemix.net
授权:Bearer eyJhbGciOiJSUzI1NiIsImp ... 。
内容类型:application / json
另一种类型的调用
curl -X GET -H授权:Bearer eyJhbGciOiJSUzI1N ....https://mobilefoundation-3b-mf-server.mybluemix。 net / imfpush / v1 / apps
错误502:无法发出令牌请求,原因:请求失败到授权服务器,服务器响应状态代码:400和正文:{" errorCode":" invalid_client"},检查授权网址:
- 使用/ imfpush服务,如下所述。
- 使用mfpadmin服务,如下所述。
在我的示例中我将使用Postman。
-
在 MobileFirst Operations Console>运行时设置>机密客户:
- 添加(只是一个示例,选择您自己的)新的
用户
客户端(id:用户
,秘密:用户
) - 添加了
apps.read
和push.application。*
范围
- 添加(只是一个示例,选择您自己的)新的
-
通过向
http:// local发出POST请求来获取访问令牌主持人:9080 / mfp / api / az / v1 / token
with:
授权标签:
- 类型:基本身份验证
- 用户:用户
- 密码:用户
正文标签:
- x-www-form-urlencoded
- grant_code:client_credentials
- 范围:apps.read push.application。*
-
通过向
http:// localhost:9080 / imfpush / v1 / apps
发出GET请求获取应用程序列表:
标题标签:
- 授权:
持票人 - access-token-from-step-2
- 授权:
-
要按平台过滤列表, URL应更改为以下内容,例如
仅获取所有应用程序的列表,使用
mfpadmin
服务应用程序
端点会更快。使用Postman:-
创建一个新的GET请求到
http:// localhost:9080 / mfpadmin / management-apis / 2.0 / runtimes / mfp / applications
您可以将域名更改为您的域名。
-
在授权标签中,我设置了以下内容:
- 类型:Basic Auth
- 用户名和密码:您的用户名和密码(到控制台)
作为回报,我收到了一份已注册的申请表。
GET /imfpush/v1/apps HTTP/1.1 Host: mobilefoundation-3b-mf-server.mybluemix.net Authorization: Bearer eyJhbGciOiJSUzI1NiIsImp.... Content-Type: application/json
another type of invocation
curl -X GET -H "Authorization: Bearer eyJhbGciOiJSUzI1N...." "https://mobilefoundation-3b-mf-server.mybluemix.net/imfpush/v1/apps"
Error 502: Failed to make token request, reason: Unsuccessful request to Authorization Server, server responded with status code: 400 and body : {"errorCode":"invalid_client"}, check the Authorization URL: http://localhost:8080/mfp/api/az/v1/token
解决方案TL;DR: right now looks like there is a bug in the
/imfpush/v1/apps
endpoint where it does not filter the applications by the vendor (APNS, GCM, WNS), so you can only get a list of all applications instead...
Note however that it all depends on your end goal. You can accomplish this by code or by using tools such as curl or Postman, Swagger etc... it all depends on what you want to achieve.
Here are 3 ways:
In the local development server - not available in Mobile Foundation service on Bluemix, you can use this URL to see the REST endpoints exposed in Swagger. You can then view push-enabled applications with this one: http://localhost:9080/doc/?url=/imfpush/v1/swagger.json#!/Applications/getAllApplications
- First, in MobileFirst Operations Console > Runtime Settings > Confidential clients:
- Add (just an example, choose your own) a new
user
client (id:user
, secret:user
) - Add the
apps.read
andpush.application.*
scopes
Be sure to click on the knob and add the
apps.read
andpush.applications.*
scopes.You will also be asked to authorize. Use the username and password for the
user
confidential client that you previously created.
- Using the /imfpush service, as described below.
- Using the mfpadmin service, as described below.
In my examples I will use Postman.
In MobileFirst Operations Console > Runtime Settings > Confidential clients:
- Added (just an example, choose your own) a new
user
client (id:user
, secret:user
) - Added the
apps.read
andpush.application.*
scopes
- Added (just an example, choose your own) a new
Obtained an access token by making a POST request to
http://localhost:9080/mfp/api/az/v1/token
with:Authorization tab:
- Type: Basic Auth
- user: user
- password: user
Body tab:
- x-www—form-urlencoded
- grant_code: client_credentials
- scope: apps.read push.application.*
Obtained the list of applications by making a GET request to
http://localhost:9080/imfpush/v1/apps
with:Headers tab:
- Authorization:
Bearer the-access-token-from-step-2
- Authorization:
To filter the list by platform, the URL should change to the following, like the example in the API documentation:
http://localhost:9080/imfpush/v1/apps/?expand=true&filter=platform==A&offset=0&size=10
But since this does not work right now... use:http://localhost:9080/imfpush/v1/apps/
Of course, you need to change
localhost
to your server's host.
To only obtain a list of all applications, it'd be faster to use the
mfpadmin
serviceapplications
endpoint. Using Postman:Created a new GET request to
http://localhost:9080/mfpadmin/management-apis/2.0/runtimes/mfp/applications
You can change the domain to yours.
In the Authorization tab, I have set the following:
- Type: Basic Auth
- Username and Password: your username and password (to the console)
In return I have received a list of registered applications.
这篇关于使用REST API检索所有应用程序列表时获取错误502的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
-