[英]How can we access oauth2 access token from springboot server using angular2
我已將授權服務器配置為public void configure(ClientDetailsServiceConfigurer客戶端)拋出異常{
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參數:
client_credentials
clientID
(來自您的配置) 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.