获取三个重要参数
钉钉登录: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
}
}
}