TokenEndpoint 类作用是获取access_token
// 类所在位置
package org.springframework.security.oauth2.provider.endpoint;
TokenEndpoint action 提供2个action方法。post为获取access_token
@RequestMapping(value = "/oauth/token", method=RequestMethod.GET)
@RequestMapping(value = "/oauth/token", method=RequestMethod.POST)
post 方法中业务逻辑是根据clientId 去数据库查询对应的用户信息。
ClientDetails authenticatedClient = getClientDetailsService().loadClientByClientId(clientId);
数据库表oauth_client_details 部分截图:
表的全部字段如下,根据你的需要去设置对应字段的值。目前我使用client_id,client_secret,authorized_grant_types,scope 。
package org.springframework.security.oauth2.provider;
public interface ClientDetails extends Serializable {
String getClientId();
Set<String> getResourceIds();
boolean isSecretRequired();
String getClientSecret();
boolean isScoped();
Set<String> getScope();
Set<String> getAuthorizedGrantTypes();
Set<String> getRegisteredRedirectUri();
Collection<GrantedAuthority> getAuthorities();
Integer getAccessTokenValiditySeconds();
Integer getRefreshTokenValiditySeconds();
boolean isAutoApprove(String scope);
Map<String, Object> getAdditionalInformation();
}