2015-10-27 92 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