项目集成钉钉登录

获取三个重要参数

钉钉登录:https://open-dev.dingtalk.com/v1/fe/old#/loginMan

在这里插入图片描述

记录以下三个信息:appId、appSecret和回调域名,后面我们会用到。
在这里插入图片描述

2. 代码

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author wql
 * @date 2021/11/19 17:24
 */
@RestController
@RequestMapping("/oauth")
public class DingDingLoginController {

    @RequestMapping("/render")
    public void renderAuth(HttpServletResponse response) throws IOException {
        AuthRequest authRequest = getAuthRequest();
        response.sendRedirect(authRequest.authorize(AuthStateUtils.createState()));
    }

    @RequestMapping("/callback")
    public Object login(AuthCallback callback) {
        AuthRequest authRequest = getAuthRequest();
        return authRequest.login(callback);
    }

    private AuthRequest getAuthRequest() {
        return new AuthDingTalkRequest(AuthConfig.builder()
                .clientId("dingoarg8xwz0o2iurhmsz")
                .clientSecret("hSlZNiq3jIEnwsMuWwsTdymUruPgc_cjXjMB4lERAAHTnz1Lh257kdu38yIJmmyE")
                .redirectUri("http://localhost:20021/oauth/callback")
                .build());
    }
}

3. 启动项目

浏览器调 render 接口即可

4. 返回数据

{
  "code": 2000,
  "msg": null,
  "data": {
    "uuid": "ebxJIZiPqeiPoeINHnTH2bRwiEiE",
    "username": "王xx",
    "nickname": "王xx",
    "avatar": null,
    "blog": null,
    "company": null,
    "location": null,
    "email": null,
    "remark": null,
    "gender": "UNKNOWN",
    "source": "DINGTALK",
    "token": {
      "accessToken": null,
      "expireIn": 0,
      "refreshToken": null,
      "refreshTokenExpireIn": 0,
      "uid": null,
      "openId": "WS6t4WUY1b79TFUVKlUc5QiEiE",
      "accessCode": null,
      "unionId": "ebxJIZiPqeiPoeINHnTH2bRwiEiE",
      "scope": null,
      "tokenType": null,
      "idToken": null,
      "macAlgorithm": null,
      "macKey": null,
      "code": null,
      "oauthToken": null,
      "oauthTokenSecret": null,
      "userId": null,
      "screenName": null,
      "oauthCallbackConfirmed": null
    },
    "rawUserInfo": {
      "nick": "王xx",
      "unionid": "ebxJIZiPqeiPoeINHnTH2bRwiEiE",
      "dingId": "$:LWCP_v1:$6h5ewoOME66PPLzmNpXts3/PN/1BM5nG",
      "openid": "WS6t4WUY1b79TFUVKlUc5QiEiE",
      "main_org_auth_high_level": true
    }
  }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Alan0517

感谢您的鼓励与支持!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值