2015-10-27 94 views
2

我试图重现这里提供的OAuth的服务器:的oauth2 Spring Security的授权码

https://spring.io/blog/2015/02/03/sso-with-oauth2-angular-js-and-spring-security-part-v 的卷曲呼叫测试这个基本的服务器应该是:

curl acme:[email protected]:9999/uaa/oauth/token \ 
-d grant_type=authorization_code -d client_id=acme  \ 
-d redirect_uri=http://example.com -d code=jYWioI 

虽然我不断收到以下错误: 授权码无效:jYWioI

此授权码在授权服务器中配置在哪里?

+0

源代码在哪里?我无法在该网站上找到它。 – johnsam

回答

2

您需要生成一个新的授权码!

您可以使用授权类型authorization_code或密码

使用authorization_code做到这一点:

打开浏览器,访问授权端点 http://localhost:9999/uaa/oauth/authorize?response_type=code&client_id=acme&redirect_uri=http://example.com

登录过程后(登录:用户密码:密码),您将被重定向到 http://example.com/?code=CODE < - 这是您应该在下一个请求中使用的代码

现在你得到的令牌:

curl acme:[email protected]:9999/uaa/oauth/token -d grant_type=authorization_code -d client_id=acme -d redirect_uri=http://example.com -d code=CODE 

响应:{ “的access_token”: “eyJhbGciOiJS .....”}

使用密码grantType:

curl acme:[email protected]:9999/uaa/oauth/token -d grant_type=password -d username=user -d password=password 

回应:{“access_token”:“eyJhbGciOiJS .....”}

我不建议d您可以阅读有关oauth grantTypes的更多信息,了解您的解决方案有哪些更好 https://aaronparecki.com/articles/2012/07/29/1/oauth2-simplified

+0

是春天自己提供的登录页面吗? – user962206