[英]Understanding OAuth2 Client credentials flow
我正在嘗試理解並實現我們的新REST服務器和現有客戶端應用程序之間的客戶端憑據流。 我已經像這樣設置了spring-security OAuth2。 根據我的理解,到目前為止,我的服務器現在應該支持以下請求:
$ curl -X -v -d 'client_id=the_client&client_secret=secret&grant_type=client_credentials' -X POST "http://localhost:9090/oauth/token"
但我明白了
InsufficientAuthenticationException: There is no client authentication
由Principal
在這里為null
引起的(spring-security code):
@FrameworkEndpoint
@RequestMapping(value = "/oauth/token")
public class TokenEndpoint extends AbstractEndpoint {
@RequestMapping
public ResponseEntity<OAuth2AccessToken> getAccessToken(Principal principal,
@RequestParam("grant_type") String grantType, @RequestParam Map<String, String> parameters) {
if (!(principal instanceof Authentication)) {
throw new InsufficientAuthenticationException(
所以看來,我需要先對服務器進行身份驗證 。 但這不是我想要做的 。 我希望我的兩台服務器使用共享密鑰互相通信。 OAuth提供程序服務器應根據請求向(受信任)客戶端服務器提供訪問令牌,以便客戶端服務器可以使用該令牌訪問服務器上的所有REST資源。 這應該保護REST資源免受外部訪問。
后來我想向第三方提供所選資源,並最終為服務器到服務器通信實現一些更細粒度的安全性。 但是現在我需要保護REST服務器免受外部訪問。
看起來我可能對整個客戶端憑證流程或彈簧安全的應用有一些誤解,因此任何澄清將非常感激。
您沒有向授權服務器驗證您的客戶端。
你需要做這樣的事情:
curl --user the_client:secret --data "grant_type=client_credentials" http://localhost:9090/oauth/token
這是向授權服務器驗證客戶端,然后指定grant_type和其他參數。 這將返回“bearer”類型的訪問令牌,其范圍由oauth客戶端詳細信息確定。 獲得令牌后,您可以通過設置Authorization標頭來訪問受保護的資源:
curl -H "Authorization: Bearer <accessToken>" <resourceUrl>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.