我们正在使用client_credentials
Apigee的OAuth 2授予流程来请求不记名令牌。根据规格:
4.4.2. Access Token Request
The client makes a request to the token endpoint by adding the
following parameters using the "application/x-www-form-urlencoded"
format per Appendix B with a character encoding of UTF-8 in the HTTP
request entity-body:
grant_type
REQUIRED. Value MUST be set to "client_credentials".
但是,如果我们拨打电话,则会收到如下错误:
{"ErrorCode" : "invalid_request", "Error" :"Required param : grant_type"}
似乎使用Apigee,我们必须将其grant_type
作为查询参数发送。
为什么是这样?由于Apigee处理OAuth 2的方式,我们有Apigee的客户无法使用他们选择的语言来使用OAuth库,所以最好知道是否有设计。
此外,它似乎grant_type
在帖子正文中不支持使用基本身份验证发送ID和密钥。
原来,您不需要grant_type
作为查询参数发送。<GrantType>
您的GenerateAccessToken策略中有一个包含变量的元素。例如,我可以使用以下代码:
<OAuthV2 name="GenerateAccessToken">
<DisplayName>GenerateAccessToken</DisplayName>
<FaultRules/>
<Properties/>
<!-- This policy generates an OAuth 2.0 access token using the password grant type -->
<Operation>GenerateAccessToken</Operation>
<!-- This is in millseconds -->
<ExpiresIn>1800000</ExpiresIn>
<Attributes/>
<SupportedGrantTypes>
<GrantType>password</GrantType>
</SupportedGrantTypes>
<GenerateResponse enabled="false">
<Format>FORM_PARAM</Format>
</GenerateResponse>
<GrantType>user.grant_type</GrantType>
<UserName>request.header.username</UserName>
<PassWord>request.header.password</PassWord>
</OAuthV2>
在此示例中,将grant_type
作为传入user.grant_type
。但user.grant_type
可以是任何内容-标头,查询参数,表单参数,甚至是硬编码的值。这样,您(开发人员)就可以以最大的灵活性来发送grant_type
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句