JustAuth使用(一) 快速入门

使用JustAuth 生成 qq 登录地址,用于网站跳转到qq登录,进行第三方登录

使用场景:

当网站需要加入第三方登录的时候, 使用 JustAuth 可以提高开发速度.

使用步骤:

1. 导入依赖

<!--JustAuth第三方登录模块-->
<dependency>
    <groupId>me.zhyd.oauth</groupId>
    <artifactId>JustAuth</artifactId>
    <version>1.13.1</version>
</dependency>

2. 配置application.yml

#============================第三方登录配置信息===================================
qq:
  app-id: 101995894
  app-secret: 238689485c7d930b7da82545505471aa
  redirect-url: http://www.shiyit.com/shiyi/oauth/callback/qq
weibo:
  app-id: 2285022919
  app-secret: a380fef0743e38cad12125902b204fab
  redirect-url: http://www.shiyit.com/callback/weibo

3. 编写工具类,能够获取第三方登录的url;返回给前端,通过window.open进行页面打开,window.open函数有三个参数,可自行查阅,达到自己想要的结果。

public class JustAuthUtils {

        public static String getAuthUrl(QqConfigProperties qqProperties,String source) {

                //1. 获取AuthRequest

                AuthRequest authRequest = getAuthRequest( qqProperties,source);

                String authUrl = authRequest.authorize(AuthStateUtils.createState();

                return R.ok().data("url",authUrl);

        }

        public static AuthRequest getAuthRequest(QqConfigProperties qqProperties,String source) {

                

        AuthRequest authRequest = null;

        switch (source) {
            case "qq":
                authRequest = new AuthQqRequest(AuthConfig.builder()
                                .clientId(qqConfigProperties.getAppId())
                                .clientSecret(qqConfigProperties.getAppSecret())
                                .redirectUri(qqConfigProperties.getRedirectUrl())
                        .build());
             break;

            default:
                break;
        }
        if(null == authRequest) {
            throw new GuliException(20001,"授权地址无效");
        }
        return authRequest;

        }       

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值