👽 AuthConfig 增加忽略校验 state 的参数

This commit is contained in:
yadong.zhang 2020-06-28 22:09:12 +08:00
parent 179287f720
commit fbeb4c68ab
2 changed files with 22 additions and 1 deletions

View File

@ -2,6 +2,7 @@ package me.zhyd.oauth.config;
import com.xkcoding.http.config.HttpConfig;
import lombok.*;
import me.zhyd.oauth.model.AuthCallback;
/**
* JustAuth配置类
@ -79,4 +80,22 @@ public class AuthConfig {
* @since 1.15.5
*/
private HttpConfig httpConfig;
/**
* 忽略校验 {@code state} 参数默认不开启 {@code ignoreCheckState} {@code true}
* {@link me.zhyd.oauth.request.AuthDefaultRequest#login(AuthCallback)} 将不会校验 {@code state} 的合法性
*
* 使用场景当且仅当使用自实现 {@code state} 校验逻辑时开启
*
* 以下场景使用方案仅作参考
* 1. 授权登录为同端并且全部使用 JustAuth 实现时该值建议设为 {@code false};
* 2. 授权和登录为不同端实现时比如前端页面拼装 {@code authorizeUrl}并且前端自行对{@code state}进行校验
* 后端只负责使用{@code code}获取用户信息时该值建议设为 {@code true};
*
* <strong>如非特殊需要不建议开启这个配置</strong>
*
* 该方案主要为了解决以下类似场景的问题
* @see <a href="https://github.com/justauth/JustAuth/issues/83">https://github.com/justauth/JustAuth/issues/83</a>
*/
private boolean ignoreCheckState;
}

View File

@ -74,7 +74,9 @@ public abstract class AuthDefaultRequest implements AuthRequest {
public AuthResponse login(AuthCallback authCallback) {
try {
AuthChecker.checkCode(source, authCallback);
AuthChecker.checkState(authCallback.getState(), source, authStateCache);
if (!config.isIgnoreCheckState()) {
AuthChecker.checkState(authCallback.getState(), source, authStateCache);
}
AuthToken authToken = this.getAccessToken(authCallback);
AuthUser user = this.getUserInfo(authToken);