code review 用户社交登陆的逻辑

增加测试页面的 README.md
pull/2/head
YunaiV 2021-12-15 09:18:15 +08:00
parent 450ca8f907
commit b365b40273
3 changed files with 33 additions and 14 deletions

View File

@ -15,16 +15,23 @@ import java.lang.reflect.Method;
/**
* request
* (使)
* 使 {@link AuthConfig}
*
* @author timfruit
* @date 2021-10-31
*/
// TODO @timfruit单测
public class YudaoAuthRequestFactory extends AuthRequestFactory {
protected JustAuthProperties properties;
protected AuthStateCache authStateCache;
/**
* configureHttpConfig private
*/
private final Method configureHttpConfigMethod = ReflectUtil.getMethod(AuthRequestFactory.class,
"configureHttpConfig", String.class, AuthConfig.class, JustAuthProperties.JustAuthHttpConfig.class);
public YudaoAuthRequestFactory(JustAuthProperties properties, AuthStateCache authStateCache) {
super(properties, authStateCache);
this.properties = properties;
@ -38,20 +45,17 @@ public class YudaoAuthRequestFactory extends AuthRequestFactory {
* @return {@link AuthRequest}
*/
public AuthRequest get(String source) {
//先尝试获取自定义扩展的
// 先尝试获取自定义扩展的
AuthRequest authRequest = getExtendRequest(source);
// 找不到,使用默认拓展
if (authRequest == null) {
authRequest = super.get(source);
}
return authRequest;
}
protected AuthRequest getExtendRequest(String source) {
AuthExtendSource authExtendSource;
try {
authExtendSource = EnumUtil.fromString(AuthExtendSource.class, source.toUpperCase());
} catch (IllegalArgumentException e) {
@ -59,19 +63,18 @@ public class YudaoAuthRequestFactory extends AuthRequestFactory {
return null;
}
// 拓展配置和默认配置齐平properties放在一起
// 拓展配置和默认配置齐平properties 放在一起
AuthConfig config = properties.getType().get(authExtendSource.name());
// 找不到对应关系,直接返回空
if (config == null) {
return null;
}
// 配置 http config
Method method = ReflectUtil.getMethod(AuthRequestFactory.class, "configureHttpConfig",
String.class, AuthConfig.class, JustAuthProperties.JustAuthHttpConfig.class);
ReflectUtil.invoke(this, method,
ReflectUtil.invoke(this, configureHttpConfigMethod,
authExtendSource.name(), config, properties.getHttpConfig());
// 获得拓展的 Request
// noinspection SwitchStatementWithTooFewBranches
switch (authExtendSource) {
case WECHAT_MINI_PROGRAM:
return new AuthWeChatMiniProgramRequest(config, authStateCache);

View File

@ -3,16 +3,19 @@ package cn.iocoder.yudao.framework.social.core.enums;
import me.zhyd.oauth.config.AuthSource;
/**
* JustAuthapiurl <br>
* JustAuthapiurl
*
* {@link me.zhyd.oauth.config.AuthDefaultSource}
* {@link me.zhyd.oauth.config.AuthDefaultSource}
*
* @author timfruit
*/
public enum AuthExtendSource implements AuthSource {
/**
*
*/
WECHAT_MINI_PROGRAM{
WECHAT_MINI_PROGRAM {
@Override
public String authorize() {
// https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/login.html

View File

@ -0,0 +1,13 @@
## 微信公众号
参考文章https://www.yuque.com/docs/share/0e2966dd-89f8-4b69-980d-b876168725df
① 访问 social-login.html 选择【微信公众号】
② 微信公众号授权完成后,跳转回 social-login2.html输入手机号 + 密码,进行绑定
## 微信小程序
参考文章https://www.yuque.com/docs/share/88e3d30a-6830-45fc-8c25-dae485aef3aa
① 暂时使用 mini-program-test 项目