簡體   English   中英

我們如何使用angular2從springboot服務器訪問oauth2訪問令牌

[英]How can we access oauth2 access token from springboot server using angular2

我已將授權服務器配置為public void configure(ClientDetailsS​​erviceConfigurer客戶端)拋出異常{

    clients.inMemory()
            .withClient("clientID")
            .authorizedGrantTypes("client-credentials", "password","refresh_token")
            .authorities("ROLE_CLIENT", "ROLE_TRUSTED_CLIENT")
            .scopes("read", "write", "trust")
            .resourceIds("oauth2-resource")
            .accessTokenValiditySeconds(120)
            .refreshTokenValiditySeconds(300)
            .secret("secret");

}

因此,基於此配置,如何從angular2應用程序獲取access_token?

使用client_credentials模式從端點/oauth/token獲取access_token (如果使用默認值)。

HTTP POST參數:

  • grant_type: client_credentials
  • client_id: clientID (來自您的配置)
  • client_secret: secret (來自您的配置)

響應結果如下:

{
    "access_token": "token...",
    "token_type": "bearer",
    "expires_in": 43199,
    "scope": "read write trust",
    "jti": "da2969c9-36e1-4177-b85e-71ed4217a036"
}

客戶端的配置(由AuthorizationServerConfigurerAdapter擴展):

@Override
public void configure(AuthorizationServerSecurityConfigurer security) throws Exception {
    security.allowFormAuthenticationForClients();
}

建議:

如果要用戶登錄,請考慮password授予模式。

另請參閱RFC6749 client_credentials

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM