spring oauth2 TokenEndpoint 源码分析(获取access_token)

本文详细介绍了Spring Security OAuth2中的TokenEndpoint类及其作用,即通过客户端ID从数据库中查询用户信息来获取access_token的过程。此外,还展示了如何通过POST请求实现这一功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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 部分截图:

214458_Eb9Y_124056.png

表的全部字段如下,根据你的需要去设置对应字段的值。目前我使用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();

}

 

 

 

转载于:https://my.oschina.net/penghaozhong/blog/791153

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值