update 优化 !pr370 完成三方登录授权功能

This commit is contained in:
疯狂的狮子Li
2023-06-20 15:00:16 +08:00
parent 50fbfe2cb4
commit 9448782f45
27 changed files with 1625 additions and 1300 deletions

View File

@ -4,7 +4,6 @@ import me.zhyd.oauth.cache.AuthStateCache;
import org.dromara.common.social.config.properties.SocialProperties;
import org.dromara.common.social.utils.AuthRedisStateCache;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
@ -17,8 +16,8 @@ import org.springframework.context.annotation.Bean;
public class SocialConfig {
@Bean
public AuthStateCache authStateCache() {
return new AuthRedisStateCache();
public AuthStateCache authStateCache(SocialProperties socialProperties) {
return new AuthRedisStateCache(socialProperties);
}
}

View File

@ -2,6 +2,11 @@ package org.dromara.common.social.config.properties;
import lombok.Data;
/**
* 社交登录配置
*
* @author thiszhc
*/
@Data
public class SocialLoginConfigProperties {

View File

@ -9,6 +9,7 @@ import java.util.Map;
/**
* Social 配置属性
*
* @author thiszhc
*/
@Data

View File

@ -1,18 +1,16 @@
package org.dromara.common.social.utils;
import jakarta.annotation.PostConstruct;
import lombok.AllArgsConstructor;
import me.zhyd.oauth.cache.AuthStateCache;
import org.dromara.common.redis.utils.RedisUtils;
import org.dromara.common.social.config.properties.SocialProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import java.time.Duration;
@AllArgsConstructor
public class AuthRedisStateCache implements AuthStateCache {
private SocialProperties socialProperties;
private final SocialProperties socialProperties;
/**
* 存入缓存
@ -22,7 +20,6 @@ public class AuthRedisStateCache implements AuthStateCache {
*/
@Override
public void cache(String key, String value) {
// TODO: 自定义存入缓存
RedisUtils.setCacheObject(key, value, Duration.ofMillis(socialProperties.getTimeout()));
}
@ -35,7 +32,6 @@ public class AuthRedisStateCache implements AuthStateCache {
*/
@Override
public void cache(String key, String value, long timeout) {
// TODO: 自定义存入缓存
RedisUtils.setCacheObject(key, value, Duration.ofMillis(timeout));
}
@ -47,7 +43,6 @@ public class AuthRedisStateCache implements AuthStateCache {
*/
@Override
public String get(String key) {
// TODO: 自定义获取缓存内容
return RedisUtils.getCacheObject(key);
}
@ -59,7 +54,6 @@ public class AuthRedisStateCache implements AuthStateCache {
*/
@Override
public boolean containsKey(String key) {
// TODO: 自定义判断key是否存在
return RedisUtils.hasKey(key);
}
}

View File

@ -1,6 +1,5 @@
package org.dromara.common.social.utils;
import me.zhyd.oauth.cache.AuthStateCache;
import me.zhyd.oauth.config.AuthConfig;
import me.zhyd.oauth.exception.AuthException;
import me.zhyd.oauth.request.*;
@ -12,10 +11,8 @@ import me.zhyd.oauth.request.*;
*/
public class SocialUtils {
public static AuthRequest getAuthRequest(String source,
String clientId,
String clientSecret,
String redirectUri) throws AuthException {
public static AuthRequest getAuthRequest(String source, String clientId,
String clientSecret, String redirectUri) throws AuthException {
AuthRequest authRequest = null;
switch (source.toLowerCase()) {
case "dingtalk" ->