Commit b365b4027397d2f4b447ae9feffabf3c782ffe64
1 parent
450ca8f9
code review 用户社交登陆的逻辑
增加测试页面的 README.md
Showing
3 changed files
with
33 additions
and
14 deletions
yudao-framework/yudao-spring-boot-starter-biz-social/src/main/java/cn/iocoder/yudao/framework/social/core/YudaoAuthRequestFactory.java
| @@ -15,16 +15,23 @@ import java.lang.reflect.Method; | @@ -15,16 +15,23 @@ import java.lang.reflect.Method; | ||
| 15 | 15 | ||
| 16 | /** | 16 | /** |
| 17 | * 第三方授权拓展 request 工厂类 | 17 | * 第三方授权拓展 request 工厂类 |
| 18 | - * (为使得拓展配置和默认配置齐平,自定义本工厂类) | 18 | + * 为使得拓展配置 {@link AuthConfig} 和默认配置齐平,所以自定义本工厂类 |
| 19 | * | 19 | * |
| 20 | * @author timfruit | 20 | * @author timfruit |
| 21 | * @date 2021-10-31 | 21 | * @date 2021-10-31 |
| 22 | */ | 22 | */ |
| 23 | +// TODO @timfruit:单测 | ||
| 23 | public class YudaoAuthRequestFactory extends AuthRequestFactory { | 24 | public class YudaoAuthRequestFactory extends AuthRequestFactory { |
| 24 | 25 | ||
| 25 | protected JustAuthProperties properties; | 26 | protected JustAuthProperties properties; |
| 26 | protected AuthStateCache authStateCache; | 27 | protected AuthStateCache authStateCache; |
| 27 | 28 | ||
| 29 | + /** | ||
| 30 | + * 由于父类 configureHttpConfig 方法是 private 修饰,所以获取后,进行反射调用 | ||
| 31 | + */ | ||
| 32 | + private final Method configureHttpConfigMethod = ReflectUtil.getMethod(AuthRequestFactory.class, | ||
| 33 | + "configureHttpConfig", String.class, AuthConfig.class, JustAuthProperties.JustAuthHttpConfig.class); | ||
| 34 | + | ||
| 28 | public YudaoAuthRequestFactory(JustAuthProperties properties, AuthStateCache authStateCache) { | 35 | public YudaoAuthRequestFactory(JustAuthProperties properties, AuthStateCache authStateCache) { |
| 29 | super(properties, authStateCache); | 36 | super(properties, authStateCache); |
| 30 | this.properties = properties; | 37 | this.properties = properties; |
| @@ -38,20 +45,17 @@ public class YudaoAuthRequestFactory extends AuthRequestFactory { | @@ -38,20 +45,17 @@ public class YudaoAuthRequestFactory extends AuthRequestFactory { | ||
| 38 | * @return {@link AuthRequest} | 45 | * @return {@link AuthRequest} |
| 39 | */ | 46 | */ |
| 40 | public AuthRequest get(String source) { | 47 | public AuthRequest get(String source) { |
| 41 | - //先尝试获取自定义扩展的 | 48 | + // 先尝试获取自定义扩展的 |
| 42 | AuthRequest authRequest = getExtendRequest(source); | 49 | AuthRequest authRequest = getExtendRequest(source); |
| 43 | - | 50 | + // 找不到,使用默认拓展 |
| 44 | if (authRequest == null) { | 51 | if (authRequest == null) { |
| 45 | authRequest = super.get(source); | 52 | authRequest = super.get(source); |
| 46 | } | 53 | } |
| 47 | - | ||
| 48 | return authRequest; | 54 | return authRequest; |
| 49 | } | 55 | } |
| 50 | 56 | ||
| 51 | - | ||
| 52 | protected AuthRequest getExtendRequest(String source) { | 57 | protected AuthRequest getExtendRequest(String source) { |
| 53 | AuthExtendSource authExtendSource; | 58 | AuthExtendSource authExtendSource; |
| 54 | - | ||
| 55 | try { | 59 | try { |
| 56 | authExtendSource = EnumUtil.fromString(AuthExtendSource.class, source.toUpperCase()); | 60 | authExtendSource = EnumUtil.fromString(AuthExtendSource.class, source.toUpperCase()); |
| 57 | } catch (IllegalArgumentException e) { | 61 | } catch (IllegalArgumentException e) { |
| @@ -59,19 +63,18 @@ public class YudaoAuthRequestFactory extends AuthRequestFactory { | @@ -59,19 +63,18 @@ public class YudaoAuthRequestFactory extends AuthRequestFactory { | ||
| 59 | return null; | 63 | return null; |
| 60 | } | 64 | } |
| 61 | 65 | ||
| 62 | - // 拓展配置和默认配置齐平,properties放在一起 | 66 | + // 拓展配置和默认配置齐平,properties 放在一起 |
| 63 | AuthConfig config = properties.getType().get(authExtendSource.name()); | 67 | AuthConfig config = properties.getType().get(authExtendSource.name()); |
| 64 | // 找不到对应关系,直接返回空 | 68 | // 找不到对应关系,直接返回空 |
| 65 | if (config == null) { | 69 | if (config == null) { |
| 66 | return null; | 70 | return null; |
| 67 | } | 71 | } |
| 68 | - | ||
| 69 | // 配置 http config | 72 | // 配置 http config |
| 70 | - Method method = ReflectUtil.getMethod(AuthRequestFactory.class, "configureHttpConfig", | ||
| 71 | - String.class, AuthConfig.class, JustAuthProperties.JustAuthHttpConfig.class); | ||
| 72 | - ReflectUtil.invoke(this, method, | 73 | + ReflectUtil.invoke(this, configureHttpConfigMethod, |
| 73 | authExtendSource.name(), config, properties.getHttpConfig()); | 74 | authExtendSource.name(), config, properties.getHttpConfig()); |
| 74 | 75 | ||
| 76 | + // 获得拓展的 Request | ||
| 77 | + // noinspection SwitchStatementWithTooFewBranches | ||
| 75 | switch (authExtendSource) { | 78 | switch (authExtendSource) { |
| 76 | case WECHAT_MINI_PROGRAM: | 79 | case WECHAT_MINI_PROGRAM: |
| 77 | return new AuthWeChatMiniProgramRequest(config, authStateCache); | 80 | return new AuthWeChatMiniProgramRequest(config, authStateCache); |
yudao-framework/yudao-spring-boot-starter-biz-social/src/main/java/cn/iocoder/yudao/framework/social/core/enums/AuthExtendSource.java
| @@ -3,16 +3,19 @@ package cn.iocoder.yudao.framework.social.core.enums; | @@ -3,16 +3,19 @@ package cn.iocoder.yudao.framework.social.core.enums; | ||
| 3 | import me.zhyd.oauth.config.AuthSource; | 3 | import me.zhyd.oauth.config.AuthSource; |
| 4 | 4 | ||
| 5 | /** | 5 | /** |
| 6 | - * 拓展JustAuth各api需要的url, 用枚举类分平台类型管理<br> | 6 | + * 拓展JustAuth各api需要的url, 用枚举类分平台类型管理 |
| 7 | * | 7 | * |
| 8 | - * 默认配置{@link me.zhyd.oauth.config.AuthDefaultSource} | 8 | + * 默认配置 {@link me.zhyd.oauth.config.AuthDefaultSource} |
| 9 | + * | ||
| 10 | + * @author timfruit | ||
| 9 | */ | 11 | */ |
| 10 | public enum AuthExtendSource implements AuthSource { | 12 | public enum AuthExtendSource implements AuthSource { |
| 11 | 13 | ||
| 12 | /** | 14 | /** |
| 13 | * 微信小程序授权登录 | 15 | * 微信小程序授权登录 |
| 14 | */ | 16 | */ |
| 15 | - WECHAT_MINI_PROGRAM{ | 17 | + WECHAT_MINI_PROGRAM { |
| 18 | + | ||
| 16 | @Override | 19 | @Override |
| 17 | public String authorize() { | 20 | public String authorize() { |
| 18 | // https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/login.html | 21 | // https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/login.html |
yudao-user-server/src/main/resources/static/READMD.md
0 → 100644
| 1 | +## 微信公众号 | ||
| 2 | + | ||
| 3 | +参考文章:https://www.yuque.com/docs/share/0e2966dd-89f8-4b69-980d-b876168725df | ||
| 4 | + | ||
| 5 | +① 访问 social-login.html 选择【微信公众号】 | ||
| 6 | + | ||
| 7 | +② 微信公众号授权完成后,跳转回 social-login2.html,输入手机号 + 密码,进行绑定 | ||
| 8 | + | ||
| 9 | +## 微信小程序 | ||
| 10 | + | ||
| 11 | +参考文章:https://www.yuque.com/docs/share/88e3d30a-6830-45fc-8c25-dae485aef3aa | ||
| 12 | + | ||
| 13 | +① 暂时使用 mini-program-test 项目 |