统一电路 OAuth2 - 为什么 Body return empty [] from REST API 请求?
Unify Circuit OAuth2 - Why does Body return empty [] from REST API requests?
当我使用我的 oauth 2.0 令牌尝试 REST API 时,我不断在 body 下返回空结果 [],在 [=81= 中返回 OK-200 状态代码].
我创建了一个机器人并使用 curl + 基本身份验证以及 swagger 测试了其余的 API,它们工作正常。我使用带有 swagger 令牌的 oauth 2.0 测试了我的 curl 命令,这也能正常工作。
我尝试了不同的设置来测试,但要坚持一个基础:
我在自定义应用程序下创建了一个机器人,选择了范围 'All' 并且 TTL 是 'Forever'。
我通过 REST 成功请求并收到了我的令牌,范围如下:'READ_USER_PROFILE,WRITE_USER_PROFILE,READ_CONVERSATIONS,WRITE_CONVERSATIONS,READ_USER'.
我注意到 'ALL' 作用域不起作用,它 returns "invalid_client, The Application null is not enabled for scope ::=[ALL]",但同一个客户端在没有上述任何作用域的情况下也能工作,或者除了 'ALL'.
我确保我有我正在测试的 REST APIs 的必要范围,例如'READ_CONVERSATIONS' 用于“/对话”
我根本没有收到任何 401 或其他错误代码,只有 200 条。
我用 swagger 生成的令牌测试了相同的命令,那个 returns 带有结果的 body 字符串(换句话说,这个令牌有效)
我已经用 Postman 和 PowerShell 的 Invoke-WebRequest/Invoke-RestMethod 复制了同样的问题。
不确定是否相关,但我注意到网络应用程序中不再存在 "OAuth Apps" 选项:"Administration" > "OAuth Apps" 下的 webclient。 "OAuth Apps" 选项卡,在 "Settings" > "Circuit Labs" 中启用 "OAuth Apps"。
\Requesting token:
curl -X POST https://circuitsandbox.net/oauth/token -d "client_id=myclientidhere&client_secret=myclientsecrethere&grant_type=client_credentials&scope=READ_USER_PROFILE,WRITE_USER_PROFILE,READ_CONVERSATIONS,WRITE_CONVERSATIONS,READ_USER" -i
{"access_token":"myaccesstokenhere","token_type":"Bearer","scope":["READ_USER_PROFILE","WRITE_USER_PROFILE","READ_CONVERSATIONS","WRITE_CONVERSATIONS","READ_USER"]}
\Making request:
curl -i "https://circuitsandbox.net/rest/v2/conversations" -H "Authorization: Bearer myaccesstokenhere" -i
[]
\\Full sample (-i parameter):
\Requesting token:
curl -X POST https://circuitsandbox.net/oauth/token -d "client_id=myclientidhere&client_secret=myclientsecrethere&grant_type=client_credentials&scope=READ_USER_PROFILE,WRITE_USER_PROFILE,READ_CONVERSATIONS,WRITE_CONVERSATIONS,READ_USER" -i
HTTP/1.1 200 OK
Date: Sat, 22 Jun 2019 01:21:43 GMT
Content-Type: application/json; charset=utf-8
Content-Length: 179
Connection: keep-alive
access-control-allow-origin: *
access-control-allow-credentials: true
access-control-allow-methods: GET, POST, DELETE, PUT, PATCH, OPTIONS
access-control-allow-headers: Accept, Accept-Language, User-Agent, Origin, Connection, Host, Accept-Encoding, Authorization, Content-Type, api_key, apiKey
ETag: W/"b3-K441G+yOERm+Qhj2E8VpkzO8ISg"
X-Frame-Options: SAMEORIGIN
X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block
Strict-Transport-Security: max-age=157680000; includeSubdomains; preload
{"access_token":"myaccesstokenhere","token_type":"Bearer","scope":["READ_USER_PROFILE","WRITE_USER_PROFILE","READ_CONVERSATIONS","WRITE_CONVERSATIONS","READ_USER"]}
\Making request:
curl -i "https://circuitsandbox.net/rest/v2/conversations" -H "Authorization: Bearer myaccesstokenhere"
HTTP/1.1 200 OK
Date: Sat, 22 Jun 2019 01:25:37 GMT
Content-Type: application/json; charset=utf-8
Content-Length: 2
Connection: keep-alive
access-control-allow-origin: *
access-control-allow-credentials: true
access-control-allow-methods: GET, POST, DELETE, PUT, PATCH, OPTIONS
access-control-allow-headers: Accept, Accept-Language, User-Agent, Origin, Connection, Host, Accept-Encoding, Authorization, Content-Type, api_key, apiKey
ETag: W/"2-l9Fw4VUO7kr8CvBlt4zaMCqXZ0w"
X-Frame-Options: SAMEORIGIN
X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block
Strict-Transport-Security: max-age=157680000; includeSubdomains; preload
[]
我希望输出包括请求的 body 输出,例如
{"type":"COMMUNITY","convId":"5fad5fa4-1097-d66f-083a-3f129214e99f","participants":["5fad5fa4-1097-d66f-083a-3f129214e99f","5fad5fa4-1097-d66f-083a-3f129214e99f","5fad5fa4-1097-d66f-083a-3f129214e99f","5fad5fa4-1097-d66f-083a-3f129214e99f"],"topic":"YourCompany","creationTime":1560992185888,"modificationTime":1561143383261,"creatorId":"5fad5fa4-1097-d66f-083a-3f129214e99f","creatorTenantId":"5fad5fa4-1097-d66f-083a-3f129214e99f","description":"Default open conversation for YourCompanyHere"}
但实际输出是:[ ]
刚刚测试过,我得到的对话(和社区)returned.This 不会 return 你的对话,而是机器人所属的对话。确保机器人是对话的成员。
如上面的回复所述,这是我遗漏的一部分,即使将机器人添加到对话中,我仍然得到空白。我也遇到了各种奇怪的问题,例如尝试将旧机器人添加到新对话等时收到错误。原因是因为我为我的电路沙箱帐户和机器人使用了相同的 e-mail 地址,所以这可能造成了冲突。简而言之,这对我有用:
1.使用与我的沙盒帐户不同的 e-mail 地址创建了新的机器人(即使是假的 e-mail 也能工作)
2。通过 e-mail 地址将机器人添加到对话中(机器人名称没有将其拉起) - 谢谢@Roger
3。 运行创建token和使用API的命令相同,这次成功了!
帮助解决问题,发布并修复同事在不同沙箱中提出的问题(感谢 Ricky El-Qasem!),在 postman、curl 和 PowerShell 中测试。
当我使用我的 oauth 2.0 令牌尝试 REST API 时,我不断在 body 下返回空结果 [],在 [=81= 中返回 OK-200 状态代码].
我创建了一个机器人并使用 curl + 基本身份验证以及 swagger 测试了其余的 API,它们工作正常。我使用带有 swagger 令牌的 oauth 2.0 测试了我的 curl 命令,这也能正常工作。
我尝试了不同的设置来测试,但要坚持一个基础:
我在自定义应用程序下创建了一个机器人,选择了范围 'All' 并且 TTL 是 'Forever'。
我通过 REST 成功请求并收到了我的令牌,范围如下:'READ_USER_PROFILE,WRITE_USER_PROFILE,READ_CONVERSATIONS,WRITE_CONVERSATIONS,READ_USER'.
我注意到 'ALL' 作用域不起作用,它 returns "invalid_client, The Application null is not enabled for scope ::=[ALL]",但同一个客户端在没有上述任何作用域的情况下也能工作,或者除了 'ALL'.
我确保我有我正在测试的 REST APIs 的必要范围,例如'READ_CONVERSATIONS' 用于“/对话”
我根本没有收到任何 401 或其他错误代码,只有 200 条。
我用 swagger 生成的令牌测试了相同的命令,那个 returns 带有结果的 body 字符串(换句话说,这个令牌有效)
我已经用 Postman 和 PowerShell 的 Invoke-WebRequest/Invoke-RestMethod 复制了同样的问题。
不确定是否相关,但我注意到网络应用程序中不再存在 "OAuth Apps" 选项:"Administration" > "OAuth Apps" 下的 webclient。 "OAuth Apps" 选项卡,在 "Settings" > "Circuit Labs" 中启用 "OAuth Apps"。
\Requesting token:
curl -X POST https://circuitsandbox.net/oauth/token -d "client_id=myclientidhere&client_secret=myclientsecrethere&grant_type=client_credentials&scope=READ_USER_PROFILE,WRITE_USER_PROFILE,READ_CONVERSATIONS,WRITE_CONVERSATIONS,READ_USER" -i
{"access_token":"myaccesstokenhere","token_type":"Bearer","scope":["READ_USER_PROFILE","WRITE_USER_PROFILE","READ_CONVERSATIONS","WRITE_CONVERSATIONS","READ_USER"]}
\Making request:
curl -i "https://circuitsandbox.net/rest/v2/conversations" -H "Authorization: Bearer myaccesstokenhere" -i
[]
\\Full sample (-i parameter):
\Requesting token:
curl -X POST https://circuitsandbox.net/oauth/token -d "client_id=myclientidhere&client_secret=myclientsecrethere&grant_type=client_credentials&scope=READ_USER_PROFILE,WRITE_USER_PROFILE,READ_CONVERSATIONS,WRITE_CONVERSATIONS,READ_USER" -i
HTTP/1.1 200 OK
Date: Sat, 22 Jun 2019 01:21:43 GMT
Content-Type: application/json; charset=utf-8
Content-Length: 179
Connection: keep-alive
access-control-allow-origin: *
access-control-allow-credentials: true
access-control-allow-methods: GET, POST, DELETE, PUT, PATCH, OPTIONS
access-control-allow-headers: Accept, Accept-Language, User-Agent, Origin, Connection, Host, Accept-Encoding, Authorization, Content-Type, api_key, apiKey
ETag: W/"b3-K441G+yOERm+Qhj2E8VpkzO8ISg"
X-Frame-Options: SAMEORIGIN
X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block
Strict-Transport-Security: max-age=157680000; includeSubdomains; preload
{"access_token":"myaccesstokenhere","token_type":"Bearer","scope":["READ_USER_PROFILE","WRITE_USER_PROFILE","READ_CONVERSATIONS","WRITE_CONVERSATIONS","READ_USER"]}
\Making request:
curl -i "https://circuitsandbox.net/rest/v2/conversations" -H "Authorization: Bearer myaccesstokenhere"
HTTP/1.1 200 OK
Date: Sat, 22 Jun 2019 01:25:37 GMT
Content-Type: application/json; charset=utf-8
Content-Length: 2
Connection: keep-alive
access-control-allow-origin: *
access-control-allow-credentials: true
access-control-allow-methods: GET, POST, DELETE, PUT, PATCH, OPTIONS
access-control-allow-headers: Accept, Accept-Language, User-Agent, Origin, Connection, Host, Accept-Encoding, Authorization, Content-Type, api_key, apiKey
ETag: W/"2-l9Fw4VUO7kr8CvBlt4zaMCqXZ0w"
X-Frame-Options: SAMEORIGIN
X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block
Strict-Transport-Security: max-age=157680000; includeSubdomains; preload
[]
我希望输出包括请求的 body 输出,例如
{"type":"COMMUNITY","convId":"5fad5fa4-1097-d66f-083a-3f129214e99f","participants":["5fad5fa4-1097-d66f-083a-3f129214e99f","5fad5fa4-1097-d66f-083a-3f129214e99f","5fad5fa4-1097-d66f-083a-3f129214e99f","5fad5fa4-1097-d66f-083a-3f129214e99f"],"topic":"YourCompany","creationTime":1560992185888,"modificationTime":1561143383261,"creatorId":"5fad5fa4-1097-d66f-083a-3f129214e99f","creatorTenantId":"5fad5fa4-1097-d66f-083a-3f129214e99f","description":"Default open conversation for YourCompanyHere"}
但实际输出是:[ ]
刚刚测试过,我得到的对话(和社区)returned.This 不会 return 你的对话,而是机器人所属的对话。确保机器人是对话的成员。
如上面的回复所述,这是我遗漏的一部分,即使将机器人添加到对话中,我仍然得到空白。我也遇到了各种奇怪的问题,例如尝试将旧机器人添加到新对话等时收到错误。原因是因为我为我的电路沙箱帐户和机器人使用了相同的 e-mail 地址,所以这可能造成了冲突。简而言之,这对我有用:
1.使用与我的沙盒帐户不同的 e-mail 地址创建了新的机器人(即使是假的 e-mail 也能工作)
2。通过 e-mail 地址将机器人添加到对话中(机器人名称没有将其拉起) - 谢谢@Roger
3。 运行创建token和使用API的命令相同,这次成功了!
帮助解决问题,发布并修复同事在不同沙箱中提出的问题(感谢 Ricky El-Qasem!),在 postman、curl 和 PowerShell 中测试。