This commit is contained in:
MaxKey 2023-03-08 14:15:52 +08:00
commit 3c7ae78543
13 changed files with 4517 additions and 0 deletions

View File

@ -0,0 +1,13 @@
# JustAuth 源码地址
https://github.com/justauth/JustAuth
# 文档地址
https://justauth.wiki/guide/quickstart/how-to-use
# 视频演示
https://b23.tv/8eZQCJD
【jeesite+ruoyi+ruoyi-vue plus+maxkey+JustAuth+oauthor2统一认证统一门户演示-哔哩哔哩】

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,52 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.jeesite</groupId>
<artifactId>jeesite-parent</artifactId>
<version>5.2.1-SNAPSHOT</version>
<relativePath>../../parent/pom.xml</relativePath>
</parent>
<artifactId>jeesite-module-maxkey</artifactId>
<packaging>jar</packaging>
<name>JeeSite Module maxkey</name>
<url>http://jeesite.com</url>
<inceptionYear>2013-Now</inceptionYear>
<dependencies>
<dependency>
<groupId>com.jeesite</groupId>
<artifactId>jeesite-module-core</artifactId>
<version>${project.parent.version}</version>
</dependency>
<dependency>
<groupId>me.zhyd.oauth</groupId>
<artifactId>JustAuth</artifactId>
<version>1.16.5</version>
</dependency>
</dependencies>
<developers>
<developer>
<id>thinkgem</id>
<name>WangZhen</name>
<email>thinkgem at 163.com</email>
<roles><role>Project lead</role></roles>
<timezone>+8</timezone>
</developer>
</developers>
<organization>
<name>JeeSite</name>
<url>http://jeesite.com</url>
</organization>
</project>

View File

@ -0,0 +1,60 @@
package com.jeesite.modules.maxkey.base;
import com.jeesite.modules.maxkey.oauth.realm.request.AuthMaxKeyJeeGitRequest;
import me.zhyd.oauth.config.AuthSource;
import me.zhyd.oauth.request.AuthDefaultRequest;
/**
* Oauth2 默认接口说明
*
* @author 长春叭哥 2023年02月23日
*
*/
public enum AuthCustomSource implements AuthSource {
/**
* 自己搭建的gitlab私服
*/
MAXKEY {
/**
* 授权的api
*
* @return url
*/
@Override
public String authorize() {
return AuthMaxKeyJeeGitRequest.BASE_HOST + "/sign/authz/oauth/v20/authorize";
}
/**
* 获取accessToken的api
*
* @return url
*/
@Override
public String accessToken() {
return AuthMaxKeyJeeGitRequest.BASE_HOST + "/sign/authz/oauth/v20/token";
}
/**
* 获取用户信息的api
*
* @return url
*/
@Override
public String userInfo() {
return AuthMaxKeyJeeGitRequest.BASE_HOST + "/sign/api/oauth/v20/me";
}
/**
* 平台对应的 AuthRequest 实现类必须继承自 {@link AuthDefaultRequest}
*
* @return class
*/
@Override
public Class<? extends AuthDefaultRequest> getTargetClass() {
return AuthMaxKeyJeeGitRequest.class;
}
}
}

View File

@ -0,0 +1,64 @@
package com.jeesite.modules.maxkey.base;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
import me.zhyd.oauth.model.AuthCallback;
/**
* 第三方授权登录 商业级版本功能实现咨询QQJeeSite彩虹1766571055
* @author 长春叭哥
* @version 2020-02-23
*/
public interface IBaseJustOauth2Controller {
/**
* Oauth2 登录
* @param source
* @param request
* @return
*/
public String login(@PathVariable("source") String source, HttpServletRequest request);
/**
* 回调地址
* @param source
* @param callback
* @param redirectAttributes
* @param model
* @param request
* @param response
* @return
*/
public String callback(@PathVariable("source") String source, AuthCallback callback, RedirectAttributes redirectAttributes, Model model, HttpServletRequest request, HttpServletResponse response);
/**
* 绑定用户
* @param id
* @param username
* @param password
* @param validCode
* @param request
* @param response
* @return
*/
public String binder(String id, String username, String password, String validCode, HttpServletRequest request, HttpServletResponse response);
/**
* 解绑用户
* @param id
* @param request
* @param response
* @return
*/
public String unbind(String id, HttpServletRequest request, HttpServletResponse response) ;
}

View File

@ -0,0 +1,118 @@
package com.jeesite.modules.maxkey.base;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
/**
*
* @author 长春叭哥
* @version 2023-02-23
*/
public enum JustAuthPlatformInfo {
/**
* 平台
*/
GITEE("Gitee", "", "", "v1.0.1", false),
BAIDU("百度", "", "", "v1.0.1", false),
CODING("coding", "", "", "v1.0.1", false),
CSDN("CSDN", "", "", "v1.0.1", false),
DINGTALK("钉钉扫码登录", "", "", "v1.0.1", false),
GITHUB("Github", "", "", "v1.0.1", false),
OSCHINA("开源中国", "", "", "v1.0.1", false),
ALIPAY("支付宝", "", "", "v1.0.1", false),
WEIBO("微博", "", "", "v1.0.1", false),
DOUYIN("抖音", "", "", "v1.4.0", false),
ELEME("饿了么", "", "", "v1.12.0", false),
FACEBOOK("Facebook", "", "", "v1.3.0", false),
GITLAB("Gitlab", "", "", "v1.11.0", false),
GOOGLE("Google", "", "", "v1.3.0", false),
HUAWEI("华为", "", "", "v1.10.0", false),
JD("京东", "", "", "v1.15.1", false),
KUJIALE("酷家乐", "", "", "v1.11.0", false),
LINKEDIN("领英", "", "", "v1.4.0", false),
MEITUAN("美团", "", "", "v1.12.0", false),
MICROSOFT("微软", "", "", "v1.5.0", false),
MI("小米", "", "", "v1.5.0", false),
PINTEREST("Pinterest", "", "", "v1.9.0", false),
QQ("QQ", "", "", "v1.1.0", false),
RENREN("人人", "", "", "v1.9.0", false),
STACK_OVERFLOW("Stack Overflow", "", "", "v1.9.0", false),
TAOBAO("淘宝", "", "", "v1.2.0", false),
TEAMBITION("Teambition", "", "", "v1.9.0", false),
WECHAT_ENTERPRISE("企业微信二维码登录", "", "", "v1.10.0", false),
WECHAT_MP("微信公众平台", "", "", "v1.14.0", false),
WECHAT_OPEN("微信开放平台", "", "", "v1.1.0", false),
TOUTIAO("今日头条", "", "", "v1.6.0-beta", false),
TWITTER("推特", "", "", "v1.13.0", false),
ALIYUN("阿里云", "", "", "v1.15.5", false),
MYGITLAB("自定义的Gitlab", "", "", "v1.13.0", false),
XMLY("喜马拉雅", "", "", "v1.15.9", false),
WECHAT_ENTERPRISE_WEB("企业微信网页登录", "", "", "v1.15.9", false),
FEISHU("飞书", "", "", "1.15.9", false),
AMAZON("Amazon", "", "", "1.16.0", true),
DINGTALK_ACCOUNT("钉钉账号登录", "", "", "v1.16.0", true),
SLACK("slack 登录", "", "", "v1.16.0", true),
LINE("line 登录", "", "", "v1.16.0", true),
okta("Okta 登录", "", "", "v1.16.0", true),
proginn("程序员客栈", "", "", "v1.16.2", true),
;
// 平台名
private final String name;
// 帮助文档
private final String readme;
// 官网api文档
private final String apiDoc;
// 集成该平台的 版本
private final String since;
private final boolean latest;
JustAuthPlatformInfo(String name, String readme, String apiDoc, String since, boolean latest) {
this.name = name;
this.readme = readme;
this.apiDoc = apiDoc;
this.since = since;
this.latest = latest;
}
public static List<Map<String, Object>> getPlatformInfos() {
List<Map<String, Object>> list = new LinkedList<>();
Map<String, Object> map = null;
JustAuthPlatformInfo[] justAuthPlatformInfos = JustAuthPlatformInfo.values();
for (JustAuthPlatformInfo justAuthPlatformInfo : justAuthPlatformInfos) {
map = new HashMap<>();
map.put("name", justAuthPlatformInfo.getName());
map.put("readme", justAuthPlatformInfo.getReadme());
map.put("apiDoc", justAuthPlatformInfo.getApiDoc());
map.put("since", justAuthPlatformInfo.getSince());
map.put("enname", justAuthPlatformInfo.name().toLowerCase());
map.put("isLatest", justAuthPlatformInfo.isLatest());
list.add(map);
}
return list;
}
public String getName() {
return name;
}
public String getReadme() {
return readme;
}
public String getApiDoc() {
return apiDoc;
}
public String getSince() {
return since;
}
public boolean isLatest() {
return latest;
}
}

View File

@ -0,0 +1,55 @@
package com.jeesite.modules.maxkey.oauth.realm.request;
import com.alibaba.fastjson.JSONObject;
import com.jeesite.common.config.Global;
import com.jeesite.common.mapper.JsonMapper;
import com.jeesite.modules.maxkey.base.AuthCustomSource;
import com.jeesite.modules.maxkey.utils.AuthCustomExceptionUtils;
import me.zhyd.oauth.cache.AuthStateCache;
import me.zhyd.oauth.config.AuthConfig;
import me.zhyd.oauth.config.AuthSource;
import me.zhyd.oauth.model.AuthCallback;
import me.zhyd.oauth.model.AuthToken;
import me.zhyd.oauth.model.AuthUser;
import me.zhyd.oauth.request.AuthDefaultRequest;
public class AuthMaxKeyJeeGitRequest extends AuthDefaultRequest {
public static final String BASE_HOST = Global.getProperty("oauth2.maxkey.serverUrl");
/**
* 设定归属域
*
* @param config
*/
public AuthMaxKeyJeeGitRequest(AuthConfig config) {
super(config, AuthCustomSource.MAXKEY);
}
public AuthMaxKeyJeeGitRequest(AuthConfig config, AuthSource source) {
super(config, source);
}
public AuthMaxKeyJeeGitRequest(AuthConfig config, AuthStateCache authStateCache) {
super(config, AuthCustomSource.MAXKEY, authStateCache);
}
@Override
protected AuthToken getAccessToken(AuthCallback authCallback) {
String body = doPostAuthorizationCode(authCallback.getCode());
JSONObject object = JSONObject.parseObject(body);
System.out.println("getAccessToken:"+JsonMapper.toJson(object));
AuthCustomExceptionUtils.checkResponse(object);
return AuthToken.builder().accessToken(object.getString("access_token")).refreshToken(object.getString("refresh_token")).idToken(object.getString("id_token")).tokenType(object.getString("token_type")).scope(object.getString("scope")).build();
}
@Override
protected AuthUser getUserInfo(AuthToken authToken) {
String body = doGetUserInfo(authToken);
JSONObject object = JSONObject.parseObject(body);
AuthCustomExceptionUtils.checkResponse(object);
return AuthUser.builder().uuid(object.getString("id")).username(object.getString("username")).nickname(object.getString("name")).avatar(object.getString("avatar_url")).blog(object.getString("web_url")).company(object.getString("organization")).location(object.getString("location")).email(object.getString("email")).remark(object.getString("bio")).token(authToken).source(source.toString()).build();
}
}

View File

@ -0,0 +1,19 @@
package com.jeesite.modules.maxkey.utils;
import com.alibaba.fastjson.JSONObject;
import me.zhyd.oauth.exception.AuthException;
public class AuthCustomExceptionUtils {
public static void checkResponse(JSONObject object) {
// oauth/token 验证异常
if (object.containsKey("error")) {
throw new AuthException(object.getString("error_description"));
}
// user 验证异常
if (object.containsKey("message")) {
throw new AuthException(object.getString("message"));
}
}
}

View File

@ -0,0 +1,404 @@
package com.jeesite.modules.maxkey.utils;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.xkcoding.http.config.HttpConfig;
import me.zhyd.oauth.config.AuthConfig;
import me.zhyd.oauth.enums.scope.*;
import me.zhyd.oauth.exception.AuthException;
import me.zhyd.oauth.request.*;
import me.zhyd.oauth.utils.AuthScopeUtils;
import java.net.InetSocketAddress;
import java.net.Proxy;
import java.util.Arrays;
import org.apache.shiro.authc.AuthenticationException;
import com.jeesite.common.config.Global;
import com.jeesite.common.shiro.authc.FormToken;
import com.jeesite.common.shiro.filter.FormFilter;
import com.jeesite.common.web.http.ServletUtils;
import com.jeesite.modules.maxkey.oauth.realm.request.AuthMaxKeyJeeGitRequest;
import com.jeesite.modules.sys.utils.UserUtils;
public class Oauth2UserLoginUtils{
private static final Boolean DEMO_MODE=true;
private static final String DEFAULT_USER_CODE="system";
public static String getAuthUserToSysUserCode(String oauthUserId) {
//自行实现第三方用户到jeesite用户之间逻辑转换关系
if(DEMO_MODE) {
return DEFAULT_USER_CODE;
}
return oauthUserId;
}
public static void loginByOauthUserId(String oauthUserId) {
HttpServletRequest request = ServletUtils.getRequest();
HttpServletResponse response = ServletUtils.getResponse();
try {
// FormToken 构造方法的三个参数登录名是否内部登录无条件请求对象
UserUtils.getSubject().login(new FormToken(getAuthUserToSysUserCode(oauthUserId), true, request));
System.out.println("登录成功__sid=" + UserUtils.getSession().getId());
FormFilter.onLoginSuccess(request, response);
} catch (AuthenticationException e) {
FormFilter.onLoginFailure(e, request, response);
}
}
/**
* 根据具体的授权来源获取授权请求工具类
*
* @param source
* @return
*/
@SuppressWarnings("deprecation")
public static AuthRequest getAuthRequest(String source) {
AuthRequest authRequest = null;
switch (source.toLowerCase()) {
case "maxkey":
// jeegit:
// clientId: 823874316692094976
// clientSecret: t74BMTcwMjIwMjMwODIzNTA4NDQFLu
// serverUrl: http://sso.maxkey.top
// redirectUri: http://localhost:8980/js/oauth2/callback/jeegit
// className: com.jeesite.modules.oauth2.request.AuthMaxKeyRequest
authRequest = new AuthMaxKeyJeeGitRequest(AuthConfig.builder()
.clientId(Global.getProperty("oauth2." + source + ".clientId"))
.clientSecret(Global.getProperty("oauth2." + source + ".clientSecret"))
.redirectUri(Global.getProperty("oauth2." + source + ".redirectUri"))
.build());
break;
case "dingtalk":
authRequest = new AuthDingTalkRequest(AuthConfig.builder()
.clientId("")
.clientSecret("")
.redirectUri("http://localhost:8443/oauth/callback/dingtalk")
.build());
break;
case "baidu":
authRequest = new AuthBaiduRequest(AuthConfig.builder()
.clientId("")
.clientSecret("")
.redirectUri("http://localhost:8443/oauth/callback/baidu")
.scopes(Arrays.asList(
AuthBaiduScope.BASIC.getScope(),
AuthBaiduScope.SUPER_MSG.getScope(),
AuthBaiduScope.NETDISK.getScope()
))
// .clientId("")
// .clientSecret("")
// .redirectUri("http://localhost:9001/oauth/baidu/callback")
.build());
break;
case "github":
authRequest = new AuthGithubRequest(AuthConfig.builder()
.clientId("")
.clientSecret("")
.redirectUri("http://localhost:8443/oauth/callback/github")
.scopes(AuthScopeUtils.getScopes(AuthGithubScope.values()))
// 针对国外平台配置代理
.httpConfig(HttpConfig.builder()
.timeout(15000)
.proxy(new Proxy(Proxy.Type.HTTP, new InetSocketAddress("127.0.0.1", 10080)))
.build())
.build());
break;
case "gitee":
authRequest = new AuthGiteeRequest(AuthConfig.builder()
.clientId("")
.clientSecret("")
.redirectUri("http://127.0.0.1:8443/oauth/callback/gitee")
.scopes(AuthScopeUtils.getScopes(AuthGiteeScope.values()))
.build());
break;
case "weibo":
authRequest = new AuthWeiboRequest(AuthConfig.builder()
.clientId("")
.clientSecret("")
.redirectUri("http://dblog-web.zhyd.me/oauth/callback/weibo")
.scopes(Arrays.asList(
AuthWeiboScope.EMAIL.getScope(),
AuthWeiboScope.FRIENDSHIPS_GROUPS_READ.getScope(),
AuthWeiboScope.STATUSES_TO_ME_READ.getScope()
))
.build());
break;
case "coding":
authRequest = new AuthCodingRequest(AuthConfig.builder()
.clientId("")
.clientSecret("")
.redirectUri("http://dblog-web.zhyd.me/oauth/callback/coding")
.domainPrefix("")
.scopes(Arrays.asList(
AuthCodingScope.USER.getScope(),
AuthCodingScope.USER_EMAIL.getScope(),
AuthCodingScope.USER_PHONE.getScope()
))
.build());
break;
case "oschina":
authRequest = new AuthOschinaRequest(AuthConfig.builder()
.clientId("")
.clientSecret("")
.redirectUri("http://localhost:8443/oauth/callback/oschina")
.build());
break;
case "alipay":
// 支付宝在创建回调地址时不允许使用localhost或者127.0.0.1所以这儿的回调地址使用的局域网内的ip
authRequest = new AuthAlipayRequest(AuthConfig.builder()
.clientId("")
.clientSecret("")
.alipayPublicKey("")
.redirectUri("https://www.zhyd.me/oauth/callback/alipay")
.build());
break;
case "qq":
authRequest = new AuthQqRequest(AuthConfig.builder()
.clientId("")
.clientSecret("")
.redirectUri("http://localhost:8443/oauth/callback/qq")
.build());
break;
case "wechat_open":
authRequest = new AuthWeChatOpenRequest(AuthConfig.builder()
.clientId("")
.clientSecret("")
.redirectUri("http://www.zhyd.me/oauth/callback/wechat")
.build());
break;
case "csdn":
authRequest = new AuthCsdnRequest(AuthConfig.builder()
.clientId("")
.clientSecret("")
.redirectUri("http://dblog-web.zhyd.me/oauth/callback/csdn")
.build());
break;
case "taobao":
authRequest = new AuthTaobaoRequest(AuthConfig.builder()
.clientId("")
.clientSecret("")
.redirectUri("http://dblog-web.zhyd.me/oauth/callback/taobao")
.build());
break;
case "google":
authRequest = new AuthGoogleRequest(AuthConfig.builder()
.clientId("")
.clientSecret("")
.redirectUri("http://localhost:8443/oauth/callback/google")
.scopes(AuthScopeUtils.getScopes(AuthGoogleScope.USER_EMAIL, AuthGoogleScope.USER_PROFILE, AuthGoogleScope.USER_OPENID))
// 针对国外平台配置代理
.httpConfig(HttpConfig.builder()
.timeout(15000)
.proxy(new Proxy(Proxy.Type.HTTP, new InetSocketAddress("127.0.0.1", 10080)))
.build())
.build());
break;
case "facebook":
authRequest = new AuthFacebookRequest(AuthConfig.builder()
.clientId("")
.clientSecret("")
.redirectUri("https://justauth.cn/oauth/callback/facebook")
.scopes(AuthScopeUtils.getScopes(AuthFacebookScope.values()))
// 针对国外平台配置代理
.httpConfig(HttpConfig.builder()
.timeout(15000)
.proxy(new Proxy(Proxy.Type.HTTP, new InetSocketAddress("127.0.0.1", 10080)))
.build())
.build());
break;
case "douyin":
authRequest = new AuthDouyinRequest(AuthConfig.builder()
.clientId("")
.clientSecret("")
.redirectUri("http://dblog-web.zhyd.me/oauth/callback/douyin")
.build());
break;
case "linkedin":
authRequest = new AuthLinkedinRequest(AuthConfig.builder()
.clientId("")
.clientSecret("")
.redirectUri("http://localhost:8443/oauth/callback/linkedin")
.scopes(null)
.build());
break;
case "microsoft":
authRequest = new AuthMicrosoftRequest(AuthConfig.builder()
.clientId("")
.clientSecret("")
.redirectUri("http://localhost:8443/oauth/callback/microsoft")
.scopes(Arrays.asList(
AuthMicrosoftScope.USER_READ.getScope(),
AuthMicrosoftScope.USER_READWRITE.getScope(),
AuthMicrosoftScope.USER_READBASIC_ALL.getScope(),
AuthMicrosoftScope.USER_READ_ALL.getScope(),
AuthMicrosoftScope.USER_READWRITE_ALL.getScope(),
AuthMicrosoftScope.USER_INVITE_ALL.getScope(),
AuthMicrosoftScope.USER_EXPORT_ALL.getScope(),
AuthMicrosoftScope.USER_MANAGEIDENTITIES_ALL.getScope(),
AuthMicrosoftScope.FILES_READ.getScope()
))
.build());
break;
case "mi":
authRequest = new AuthMiRequest(AuthConfig.builder()
.clientId("")
.clientSecret("")
.redirectUri("http://dblog-web.zhyd.me/oauth/callback/mi")
.build());
break;
case "toutiao":
authRequest = new AuthToutiaoRequest(AuthConfig.builder()
.clientId("")
.clientSecret("")
.redirectUri("http://dblog-web.zhyd.me/oauth/callback/toutiao")
.build());
break;
case "teambition":
authRequest = new AuthTeambitionRequest(AuthConfig.builder()
.clientId("")
.clientSecret("")
.redirectUri("http://127.0.0.1:8443/oauth/callback/teambition")
.build());
break;
case "pinterest":
authRequest = new AuthPinterestRequest(AuthConfig.builder()
.clientId("")
.clientSecret("")
.redirectUri("https://eadmin.innodev.com.cn/oauth/callback/pinterest")
// 针对国外平台配置代理
.httpConfig(HttpConfig.builder()
.timeout(15000)
.proxy(new Proxy(Proxy.Type.HTTP, new InetSocketAddress("127.0.0.1", 10080)))
.build())
.build());
break;
case "renren":
authRequest = new AuthRenrenRequest(AuthConfig.builder()
.clientId("")
.clientSecret("")
.redirectUri("http://127.0.0.1:8443/oauth/callback/teambition")
.build());
break;
case "stack_overflow":
authRequest = new AuthStackOverflowRequest(AuthConfig.builder()
.clientId("")
.clientSecret("((")
.redirectUri("http://localhost:8443/oauth/callback/stack_overflow")
.stackOverflowKey("")
.build());
break;
case "huawei":
authRequest = new AuthHuaweiRequest(AuthConfig.builder()
.clientId("")
.clientSecret("")
.redirectUri("http://127.0.0.1:8443/oauth/callback/huawei")
.scopes(Arrays.asList(
AuthHuaweiScope.BASE_PROFILE.getScope(),
AuthHuaweiScope.MOBILE_NUMBER.getScope(),
AuthHuaweiScope.ACCOUNTLIST.getScope(),
AuthHuaweiScope.SCOPE_DRIVE_FILE.getScope(),
AuthHuaweiScope.SCOPE_DRIVE_APPDATA.getScope()
))
.build());
break;
case "wechat_enterprise":
authRequest = new AuthWeChatEnterpriseQrcodeRequest(AuthConfig.builder()
.clientId("")
.clientSecret("")
.redirectUri("http://justauth.cn/oauth/callback/wechat_enterprise")
.agentId("1000003")
.build());
break;
case "kujiale":
authRequest = new AuthKujialeRequest(AuthConfig.builder()
.clientId("")
.clientSecret("")
.redirectUri("http://dblog-web.zhyd.me/oauth/callback/kujiale")
.build());
break;
case "gitlab":
authRequest = new AuthGitlabRequest(AuthConfig.builder()
.clientId("")
.clientSecret("")
.redirectUri("http://localhost:8443/oauth/callback/gitlab")
.scopes(AuthScopeUtils.getScopes(AuthGitlabScope.values()))
.build());
break;
case "meituan":
authRequest = new AuthMeituanRequest(AuthConfig.builder()
.clientId("")
.clientSecret("")
.redirectUri("http://localhost:8443/oauth/callback/meituan")
.build());
break;
case "eleme":
authRequest = new AuthElemeRequest(AuthConfig.builder()
.clientId("")
.clientSecret("")
.redirectUri("http://dblog-web.zhyd.me/oauth/callback/eleme")
.build());
break;
case "twitter":
authRequest = new AuthTwitterRequest(AuthConfig.builder()
.clientId("")
.clientSecret("")
.redirectUri("https://threelogin.31huiyi.com/oauth/callback/twitter")
// 针对国外平台配置代理
.httpConfig(HttpConfig.builder()
.timeout(15000)
.proxy(new Proxy(Proxy.Type.HTTP, new InetSocketAddress("127.0.0.1", 10080)))
.build())
.build());
break;
case "wechat_mp":
authRequest = new AuthWeChatMpRequest(AuthConfig.builder()
.clientId("")
.clientSecret("")
.redirectUri("")
.build());
break;
case "aliyun":
authRequest = new AuthAliyunRequest(AuthConfig.builder()
.clientId("")
.clientSecret("")
.redirectUri("http://localhost:8443/oauth/callback/aliyun")
.build());
break;
case "xmly":
authRequest = new AuthXmlyRequest(AuthConfig.builder()
.clientId("")
.clientSecret("")
.redirectUri("http://localhost:8443/oauth/callback/xmly")
.build());
break;
case "feishu":
authRequest = new AuthFeishuRequest(AuthConfig.builder()
.clientId("")
.clientSecret("")
.redirectUri("http://localhost:8443/oauth/callback/feishu")
.build());
break;
default:
break;
}
if (null == authRequest) {
throw new AuthException("未获取到有效的Auth配置");
}
return authRequest;
}
}

View File

@ -0,0 +1,82 @@
package com.jeesite.modules.maxkey.web;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
import com.jeesite.common.config.Global;
import com.jeesite.common.mapper.JsonMapper;
import com.jeesite.common.web.BaseController;
import com.jeesite.modules.maxkey.base.IBaseJustOauth2Controller;
import com.jeesite.modules.maxkey.utils.Oauth2UserLoginUtils;
import me.zhyd.oauth.model.AuthCallback;
import me.zhyd.oauth.model.AuthResponse;
import me.zhyd.oauth.model.AuthUser;
import me.zhyd.oauth.request.AuthRequest;
import me.zhyd.oauth.utils.AuthStateUtils;
/**
* 推荐参考案例https://github.com/justauth/JustAuth-demo/blob/master/src/main/java/me/zhyd/justauth/RestAuthController.java
* JustAuth 控制层
*
* @author 长春叭哥
* @version 2023-02-23
*/
@Controller
@RequestMapping({ "/oauth2" })
public class JustOauth2Controller extends BaseController implements IBaseJustOauth2Controller {
@Override
@RequestMapping({"/login/{source}"})
public String login(String source, HttpServletRequest request) {
// TODO Auto-generated method stub
logger.debug(source);
return "redirect:" + Oauth2UserLoginUtils.getAuthRequest(source).authorize((request.getParameter("state") == null ? AuthStateUtils.createState() : request.getParameter("state")));
}
@Override
@RequestMapping({"/callback/{source}"})
public String callback(String source, AuthCallback callback, RedirectAttributes redirectAttributes, Model model, HttpServletRequest request, HttpServletResponse response) {
// TODO Auto-generated method stub
logger.debug(source);
AuthRequest authRequest = Oauth2UserLoginUtils.getAuthRequest(source);
AuthResponse<?> rauthResponse = authRequest.login(callback);
if(rauthResponse.getData() instanceof AuthUser) {
AuthUser authUser = (AuthUser) rauthResponse.getData();
//处理相关的绑定业务该处仅做简单集成与演示专用
logger.debug("authUser:"+JsonMapper.toJson(authUser));
Oauth2UserLoginUtils.loginByOauthUserId(authUser.getUsername());
return renderResult(Global.TRUE, text("回调信息获取成功!"));
} else {
return null;
}
}
@Override
@PostMapping({"/binder"})
@ResponseBody
public String binder(String id, String username, String password, String validCode, HttpServletRequest request, HttpServletResponse response) {
// TODO Auto-generated method stub
logger.debug(id, username);
return null;
}
@Override
@RequestMapping({"/unbind"})
@ResponseBody
public String unbind(String id, HttpServletRequest request, HttpServletResponse response) {
// TODO Auto-generated method stub
logger.debug(id);
return null;
}
}

View File

@ -0,0 +1,59 @@
# 温馨提示不建议直接修改此文件为了平台升级方便建议将需要修改的参数值复制到application.yml里进行覆盖该参数值。
#maxkey:
# enabled: true
oauth2:
# 码云
maxkey:
clientId: 821060415982141440
clientSecret: MrjGMDkwMjIwMjMxNTE0MzkxODAv5o
serverUrl: http://sso.maxkey.top
redirectUri: http://localhost:8981/js/oauth2/callback/maxkey
className: com.jeesite.modules.maxkey.oauth.realm.request.AuthMaxKeyJeeGitRequest
gitee:
clientId: xxxxxx
clientSecret: xxxxxx
redirectUri: http://127.0.0.1:8980/js/oauth2/callback/gitee
# 腾讯QQ
qq:
clientId: xxxxxx
clientSecret: xxxxxx
redirectUri: http://127.0.0.1:8980/js/oauth2/callback/qq
unionid: xxxxxx
# 微信开放平台
weixin:
clientId: xxxxxx
clientSecret: xxxxxx
redirectUri: http://127.0.0.1:8980/js/oauth2/callback/weixin
# 微信公众平台
weixin_mp:
clientId: xxxxxx
clientSecret: xxxxxx
redirectUri: http://127.0.0.1:8980/js/oauth2/callback/weixin_mp
# 企业微信
weixin_qy:
clientId: xxxxxx
clientSecret: xxxxxx
redirectUri: http://127.0.0.1:8980/js/oauth2/callback/weixin_qy
agentId: xxxxxx
# 钉钉
ding_talk:
clientId: xxxxxx
clientSecret: xxxxxx
redirectUri: http://127.0.0.1:8980/js/oauth2/callback/ding_talk
# Github
github:
clientId: xxxxxx
clientSecret: xxxxxx
redirectUri: http://127.0.0.1:8980/js/oauth2/callback/github
# 百度
baidu:
clientId: xxxxxx
clientSecret: xxxxxx
redirectUri: http://127.0.0.1:8980/js/oauth2/callback/baidu