简体   繁体   English

Symfony2 FOSOAuthServerBundle授予类型密码需要客户端密码

[英]Symfony2 FOSOAuthServerBundle grant type password requires client secret

I'm integrating FOSOAuthServerBundle to handle login from a mobile app to a Symfony2 backoffice. 我正在集成FOSOAuthServerBundle,以处理从移动应用到Symfony2后台的登录。 I've followed the instructions of this answer , but as I've never used OAuth2 before I'm a bit lost sometimes. 我已经按照此答案的说明进行操作,但是由于我从未使用过OAuth2 ,因此有时会有点迷路。

I tried logging in using the 'password' grant_type but for some reason it won't work unless I specify the client_secret as a GET parameter. 我尝试使用“密码” grant_type登录,但是由于某些原因,除非我将client_secret指定为GET参数,否则它将无法正常工作。 Am I actually supposed to ? 我真的应该吗?

Here's what my request looks like: 这是我的要求:

http://myserv.local/app_dev.php/oauth/v2/token ?client_id=1_4up4x3hpaask4g0sok0so8sg00gk48c44cc0wkwwsg8048wcog &grant_type=password &username=test@test.com &password=somepassword

It returns this response unless the client_secret parameter is added: 除非添加了client_secret参数,否则它将返回此响应:

{"error":"invalid_client","error_description":"The client credentials are invalid"}

Yes, you are supposed to include the client secret. 是的,您应该包括客户机密。 Once you make this request, you will get an access_token that can be used with each each future request so that you don't need to use the credentials or client info again until the access_token expires. 发出此请求后,您将获得一个access_token,该令牌可与以后的每个请求一起使用,这样,在access_token到期之前,您无需再次使用凭据或客户端信息。 And when the token expires, even then you won't need to use the user credentials again, you can use the refresh_token, along with the client id and secret to get a new access_token. 而且,当令牌过期时,即使这样,您也无需再次使用用户凭据,您可以使用refresh_token以及客户端ID和密码来获取新的access_token。 So your initial request should look like this: 因此,您的初始请求应如下所示:

http://localhost/oauth/v2/token?client_id=[CLIENT_ID]&client_secret=[SECRET]&grant_type=password&username=[USERNAME]&password=[PASSWORD]

and in the response, you would get the access_token, which can be used like this: 并且在响应中,您将获得access_token,可以像这样使用:

http://localhost/api/users?access_token=[ACCESS_TOKEN]

hopefully this clarifies a little more for you. 希望这可以为您澄清更多。

当您使用唯一允许的授予类型“ password”创建一个新客户端时,这应该不是客户端机密是公开的安全问题,并且没有人可以在client_credential授予中使用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM