mirror of
https://gitee.com/dromara/sa-token.git
synced 2024-11-29 18:37:49 +08:00
feat(oauth2): 新增 SaOAuth2Util.getCode
等方法,以更方便的获取、校验授权码。
This commit is contained in:
parent
4e70438ba8
commit
494030506d
@ -364,6 +364,43 @@ public class SaOAuth2Template {
|
||||
}
|
||||
|
||||
|
||||
// ----------------- Code 相关 -----------------
|
||||
|
||||
/**
|
||||
* 获取 CodeModel,无效的 code 会返回 null
|
||||
* @param code /
|
||||
* @return /
|
||||
*/
|
||||
public CodeModel getCode(String code) {
|
||||
return SaOAuth2Manager.getDao().getCode(code);
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验 Code,成功返回 CodeModel,失败则抛出异常
|
||||
* @param code /
|
||||
* @return /
|
||||
*/
|
||||
public CodeModel checkCode(String code) {
|
||||
CodeModel cm = SaOAuth2Manager.getDao().getCode(code);
|
||||
if(cm == null) {
|
||||
throw new SaOAuth2AuthorizationCodeException("无效 code: " + code)
|
||||
.setAuthorizationCode(code)
|
||||
.setCode(SaOAuth2ErrorCode.CODE_30110);
|
||||
}
|
||||
return cm;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取 Code,根据索引: clientId、loginId
|
||||
* @param clientId /
|
||||
* @param loginId /
|
||||
* @return /
|
||||
*/
|
||||
public String getCodeValue(String clientId, Object loginId) {
|
||||
return SaOAuth2Manager.getDao().getCodeValue(clientId, loginId);
|
||||
}
|
||||
|
||||
|
||||
// ----------------- Access-Token 相关 -----------------
|
||||
|
||||
/**
|
||||
|
@ -16,9 +16,9 @@
|
||||
package cn.dev33.satoken.oauth2.template;
|
||||
|
||||
import cn.dev33.satoken.oauth2.SaOAuth2Manager;
|
||||
import cn.dev33.satoken.oauth2.dao.SaOAuth2Dao;
|
||||
import cn.dev33.satoken.oauth2.data.model.AccessTokenModel;
|
||||
import cn.dev33.satoken.oauth2.data.model.ClientTokenModel;
|
||||
import cn.dev33.satoken.oauth2.data.model.CodeModel;
|
||||
import cn.dev33.satoken.oauth2.data.model.RefreshTokenModel;
|
||||
import cn.dev33.satoken.oauth2.data.model.loader.SaClientModel;
|
||||
|
||||
@ -129,6 +129,37 @@ public class SaOAuth2Util {
|
||||
}
|
||||
|
||||
|
||||
// ----------------- Code 相关 -----------------
|
||||
|
||||
/**
|
||||
* 获取 CodeModel,无效的 code 会返回 null
|
||||
* @param code /
|
||||
* @return /
|
||||
*/
|
||||
public static CodeModel getCode(String code) {
|
||||
return SaOAuth2Manager.getTemplate().getCode(code);
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验 Code,成功返回 CodeModel,失败则抛出异常
|
||||
* @param code /
|
||||
* @return /
|
||||
*/
|
||||
public static CodeModel checkCode(String code) {
|
||||
return SaOAuth2Manager.getTemplate().checkCode(code);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取 Code,根据索引: clientId、loginId
|
||||
* @param clientId /
|
||||
* @param loginId /
|
||||
* @return /
|
||||
*/
|
||||
public static String getCodeValue(String clientId, Object loginId) {
|
||||
return SaOAuth2Manager.getTemplate().getCodeValue(clientId, loginId);
|
||||
}
|
||||
|
||||
|
||||
// ----------------- Access-Token 相关 -----------------
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user