提交 6541f854 编写于 作者: 智布道's avatar 智布道 👁

JustAuth升级到1.10.0

上级 6e054bd2
package com.zyd.blog.business.service;
import me.zhyd.oauth.model.AuthCallback;
/**
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
* @version 1.0
......@@ -9,7 +11,7 @@ package com.zyd.blog.business.service;
*/
public interface AuthService {
boolean login(String source, String code, String auth_code);
boolean login(String source, AuthCallback callback);
boolean revoke(String source, Long userId);
......
......@@ -6,7 +6,6 @@ import com.zyd.blog.business.entity.User;
import com.zyd.blog.business.entity.UserPwd;
import com.zyd.blog.business.vo.UserConditionVO;
import com.zyd.blog.framework.object.AbstractService;
import me.zhyd.oauth.model.AuthSource;
import java.util.List;
......
......@@ -8,12 +8,12 @@ import com.zyd.blog.plugin.oauth.RequestFactory;
import com.zyd.blog.util.BeanConvertUtil;
import com.zyd.blog.util.SessionUtil;
import lombok.extern.slf4j.Slf4j;
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 org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
/**
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
......@@ -30,9 +30,9 @@ public class AuthServiceImpl implements AuthService {
private SysUserService userService;
@Override
public boolean login(String source, String code, String auth_code) {
public boolean login(String source, AuthCallback callback) {
AuthRequest authRequest = RequestFactory.getInstance(source).getRequest();
AuthResponse response = authRequest.login(StringUtils.isEmpty(code) ? auth_code : code);
AuthResponse response = authRequest.login(callback);
if (response.ok()) {
AuthUser authUser = (AuthUser) response.getData();
User newUser = BeanConvertUtil.doConvert(authUser, User.class);
......
......@@ -36,4 +36,16 @@ public class JustAuthProperties {
private AuthConfig google;
private AuthConfig facebook;
private AuthConfig csdn;
private AuthConfig douyin;
private AuthConfig linkedin;
private AuthConfig microsoft;
private AuthConfig mi;
private AuthConfig toutiao;
private AuthConfig teambition;
private AuthConfig renren;
private AuthConfig pinterest;
private AuthConfig stackoverflow;
private AuthConfig huawei;
private AuthConfig wechatEnterprise;
}
......@@ -8,7 +8,8 @@ import com.zyd.blog.framework.property.JustAuthProperties;
import com.zyd.blog.util.SessionUtil;
import lombok.extern.slf4j.Slf4j;
import me.zhyd.oauth.config.AuthConfig;
import me.zhyd.oauth.utils.AuthConfigChecker;
import me.zhyd.oauth.config.AuthSource;
import me.zhyd.oauth.utils.AuthChecker;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
......@@ -133,16 +134,20 @@ public class CustomTags extends BaseTag {
for (Field f : authProperties.getClass().getDeclaredFields()) {
f.setAccessible(true);
String fieldName = f.getName();
AuthSource source = null;
if ("tencentCloud".equals(fieldName)) {
source = AuthSource.TENCENT_CLOUD;
} else if ("stackoverflow".equals(fieldName)) {
source = AuthSource.STACK_OVERFLOW;
} else if ("wechatEnterprise".equals(fieldName)) {
source = AuthSource.WECHAT_ENTERPRISE;
} else {
source = AuthSource.valueOf(fieldName.toUpperCase());
}
AuthConfig authConfig = (AuthConfig) f.get(authProperties);
if (null != authConfig) {
if (AuthConfigChecker.isSupportedAuth(authConfig)) {
if ("alipay".equals(fieldName)) {
if (!StringUtils.isEmpty(authConfig.getAlipayPublicKey())) {
list.add(fieldName);
}
} else {
list.add(fieldName);
}
if (AuthChecker.isSupportedAuth(authConfig, source)) {
list.add(fieldName);
}
}
......
package com.zyd.blog.plugin.oauth;
import com.zyd.blog.framework.property.JustAuthProperties;
import me.zhyd.oauth.config.AuthConfig;
import me.zhyd.oauth.request.AuthDouyinRequest;
import me.zhyd.oauth.request.AuthRequest;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
* @version 1.0
* @website https://www.zhyd.me
* @date 2019/8/7 21:37
* @since 1.8
*/
@Component
public class DouyinRequest implements OauthRequest, InitializingBean {
@Autowired
private JustAuthProperties properties;
@Override
public AuthRequest getRequest() {
AuthConfig authConfig = properties.getDouyin();
return new AuthDouyinRequest(AuthConfig.builder()
.clientId(authConfig.getClientId())
.clientSecret(authConfig.getClientSecret())
.redirectUri(authConfig.getRedirectUri())
.build());
}
@Override
public void afterPropertiesSet() throws Exception {
RequestFactory.registerRequest("douyin", this);
}
}
package com.zyd.blog.plugin.oauth;
import com.zyd.blog.framework.property.JustAuthProperties;
import me.zhyd.oauth.config.AuthConfig;
import me.zhyd.oauth.request.AuthHuaweiRequest;
import me.zhyd.oauth.request.AuthRequest;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
* @version 1.0
* @website https://www.zhyd.me
* @date 2019/8/7 21:37
* @since 1.8
*/
@Component
public class HuaweiRequest implements OauthRequest, InitializingBean {
@Autowired
private JustAuthProperties properties;
@Override
public AuthRequest getRequest() {
AuthConfig authConfig = properties.getHuawei();
return new AuthHuaweiRequest(AuthConfig.builder()
.clientId(authConfig.getClientId())
.clientSecret(authConfig.getClientSecret())
.redirectUri(authConfig.getRedirectUri())
.build());
}
@Override
public void afterPropertiesSet() throws Exception {
RequestFactory.registerRequest("huawei", this);
}
}
package com.zyd.blog.plugin.oauth;
import com.zyd.blog.framework.property.JustAuthProperties;
import me.zhyd.oauth.config.AuthConfig;
import me.zhyd.oauth.request.AuthLinkedinRequest;
import me.zhyd.oauth.request.AuthRequest;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
* @version 1.0
* @website https://www.zhyd.me
* @date 2019/8/7 21:37
* @since 1.8
*/
@Component
public class LinkedinRequest implements OauthRequest, InitializingBean {
@Autowired
private JustAuthProperties properties;
@Override
public AuthRequest getRequest() {
AuthConfig authConfig = properties.getLinkedin();
return new AuthLinkedinRequest(AuthConfig.builder()
.clientId(authConfig.getClientId())
.clientSecret(authConfig.getClientSecret())
.redirectUri(authConfig.getRedirectUri())
.build());
}
@Override
public void afterPropertiesSet() throws Exception {
RequestFactory.registerRequest("linkedin", this);
}
}
package com.zyd.blog.plugin.oauth;
import com.zyd.blog.framework.property.JustAuthProperties;
import me.zhyd.oauth.config.AuthConfig;
import me.zhyd.oauth.request.AuthMiRequest;
import me.zhyd.oauth.request.AuthRequest;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
* @version 1.0
* @website https://www.zhyd.me
* @date 2019/8/7 21:37
* @since 1.8
*/
@Component
public class MiRequest implements OauthRequest, InitializingBean {
@Autowired
private JustAuthProperties properties;
@Override
public AuthRequest getRequest() {
AuthConfig authConfig = properties.getMi();
return new AuthMiRequest(AuthConfig.builder()
.clientId(authConfig.getClientId())
.clientSecret(authConfig.getClientSecret())
.redirectUri(authConfig.getRedirectUri())
.build());
}
@Override
public void afterPropertiesSet() throws Exception {
RequestFactory.registerRequest("mi", this);
}
}
package com.zyd.blog.plugin.oauth;
import com.zyd.blog.framework.property.JustAuthProperties;
import me.zhyd.oauth.config.AuthConfig;
import me.zhyd.oauth.request.AuthMicrosoftRequest;
import me.zhyd.oauth.request.AuthRequest;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
* @version 1.0
* @website https://www.zhyd.me
* @date 2019/8/7 21:37
* @since 1.8
*/
@Component
public class MicrosoftRequest implements OauthRequest, InitializingBean {
@Autowired
private JustAuthProperties properties;
@Override
public AuthRequest getRequest() {
AuthConfig authConfig = properties.getMicrosoft();
return new AuthMicrosoftRequest(AuthConfig.builder()
.clientId(authConfig.getClientId())
.clientSecret(authConfig.getClientSecret())
.redirectUri(authConfig.getRedirectUri())
.build());
}
@Override
public void afterPropertiesSet() throws Exception {
RequestFactory.registerRequest("microsoft", this);
}
}
package com.zyd.blog.plugin.oauth;
import com.zyd.blog.framework.property.JustAuthProperties;
import me.zhyd.oauth.config.AuthConfig;
import me.zhyd.oauth.request.AuthPinterestRequest;
import me.zhyd.oauth.request.AuthRequest;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
* @version 1.0
* @website https://www.zhyd.me
* @date 2019/8/7 21:37
* @since 1.8
*/
@Component
public class PinterestRequest implements OauthRequest, InitializingBean {
@Autowired
private JustAuthProperties properties;
@Override
public AuthRequest getRequest() {
AuthConfig authConfig = properties.getPinterest();
return new AuthPinterestRequest(AuthConfig.builder()
.clientId(authConfig.getClientId())
.clientSecret(authConfig.getClientSecret())
.redirectUri(authConfig.getRedirectUri())
.build());
}
@Override
public void afterPropertiesSet() throws Exception {
RequestFactory.registerRequest("pinterest", this);
}
}
package com.zyd.blog.plugin.oauth;
import com.zyd.blog.framework.property.JustAuthProperties;
import me.zhyd.oauth.config.AuthConfig;
import me.zhyd.oauth.request.AuthRenrenRequest;
import me.zhyd.oauth.request.AuthRequest;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
* @version 1.0
* @website https://www.zhyd.me
* @date 2019/8/7 21:37
* @since 1.8
*/
@Component
public class RenrenRequest implements OauthRequest, InitializingBean {
@Autowired
private JustAuthProperties properties;
@Override
public AuthRequest getRequest() {
AuthConfig authConfig = properties.getRenren();
return new AuthRenrenRequest(AuthConfig.builder()
.clientId(authConfig.getClientId())
.clientSecret(authConfig.getClientSecret())
.redirectUri(authConfig.getRedirectUri())
.build());
}
@Override
public void afterPropertiesSet() throws Exception {
RequestFactory.registerRequest("renren", this);
}
}
package com.zyd.blog.plugin.oauth;
import com.zyd.blog.framework.property.JustAuthProperties;
import me.zhyd.oauth.config.AuthConfig;
import me.zhyd.oauth.request.AuthRequest;
import me.zhyd.oauth.request.AuthStackOverflowRequest;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
* @version 1.0
* @website https://www.zhyd.me
* @date 2019/8/7 21:37
* @since 1.8
*/
@Component
public class StackoverflowRequest implements OauthRequest, InitializingBean {
@Autowired
private JustAuthProperties properties;
@Override
public AuthRequest getRequest() {
AuthConfig authConfig = properties.getStackoverflow();
return new AuthStackOverflowRequest(AuthConfig.builder()
.clientId(authConfig.getClientId())
.clientSecret(authConfig.getClientSecret())
.redirectUri(authConfig.getRedirectUri())
.stackOverflowKey(authConfig.getStackOverflowKey())
.build());
}
@Override
public void afterPropertiesSet() throws Exception {
RequestFactory.registerRequest("stackoverflow", this);
}
}
package com.zyd.blog.plugin.oauth;
import com.zyd.blog.framework.property.JustAuthProperties;
import me.zhyd.oauth.config.AuthConfig;
import me.zhyd.oauth.request.AuthRequest;
import me.zhyd.oauth.request.AuthTeambitionRequest;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
* @version 1.0
* @website https://www.zhyd.me
* @date 2019/8/7 21:37
* @since 1.8
*/
@Component
public class TeambitionRequest implements OauthRequest, InitializingBean {
@Autowired
private JustAuthProperties properties;
@Override
public AuthRequest getRequest() {
AuthConfig authConfig = properties.getTeambition();
return new AuthTeambitionRequest(AuthConfig.builder()
.clientId(authConfig.getClientId())
.clientSecret(authConfig.getClientSecret())
.redirectUri(authConfig.getRedirectUri())
.build());
}
@Override
public void afterPropertiesSet() throws Exception {
RequestFactory.registerRequest("teambition", this);
}
}
package com.zyd.blog.plugin.oauth;
import com.zyd.blog.framework.property.JustAuthProperties;
import me.zhyd.oauth.config.AuthConfig;
import me.zhyd.oauth.request.AuthRequest;
import me.zhyd.oauth.request.AuthToutiaoRequest;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
* @version 1.0
* @website https://www.zhyd.me
* @date 2019/8/7 21:37
* @since 1.8
*/
@Component
public class ToutiaoRequest implements OauthRequest, InitializingBean {
@Autowired
private JustAuthProperties properties;
@Override
public AuthRequest getRequest() {
AuthConfig authConfig = properties.getToutiao();
return new AuthToutiaoRequest(AuthConfig.builder()
.clientId(authConfig.getClientId())
.clientSecret(authConfig.getClientSecret())
.redirectUri(authConfig.getRedirectUri())
.build());
}
@Override
public void afterPropertiesSet() throws Exception {
RequestFactory.registerRequest("toutiao", this);
}
}
package com.zyd.blog.plugin.oauth;
import com.zyd.blog.framework.property.JustAuthProperties;
import me.zhyd.oauth.config.AuthConfig;
import me.zhyd.oauth.request.AuthRequest;
import me.zhyd.oauth.request.AuthWeChatEnterpriseRequest;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
* @version 1.0
* @website https://www.zhyd.me
* @date 2019/8/7 21:37
* @since 1.8
*/
@Component
public class WechatEnterpriseRequest implements OauthRequest, InitializingBean {
@Autowired
private JustAuthProperties properties;
@Override
public AuthRequest getRequest() {
AuthConfig authConfig = properties.getWechatEnterprise();
return new AuthWeChatEnterpriseRequest(AuthConfig.builder()
.clientId(authConfig.getClientId())
.clientSecret(authConfig.getClientSecret())
.redirectUri(authConfig.getRedirectUri())
.agentId(authConfig.getAgentId())
.build());
}
@Override
public void afterPropertiesSet() throws Exception {
RequestFactory.registerRequest("wechatEnterprise", this);
}
}
......@@ -4,9 +4,11 @@ import com.zyd.blog.business.service.AuthService;
import com.zyd.blog.plugin.oauth.RequestFactory;
import com.zyd.blog.util.RequestUtil;
import com.zyd.blog.util.ResultUtil;
import me.zhyd.oauth.model.AuthCallback;
import me.zhyd.oauth.model.AuthResponse;
import me.zhyd.oauth.model.AuthToken;
import me.zhyd.oauth.request.AuthRequest;
import me.zhyd.oauth.utils.AuthStateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
......@@ -36,20 +38,19 @@ public class OAuthController {
public void renderAuth(@PathVariable("source") String source, HttpServletResponse response, HttpSession session) throws IOException {
AuthRequest authRequest = RequestFactory.getInstance(source).getRequest();
session.setAttribute("historyUrl", RequestUtil.getReferer());
response.sendRedirect(authRequest.authorize());
response.sendRedirect(authRequest.authorize(AuthStateUtils.createState()));
}
/**
* 授权回调地址
*
* @param source 授权回调来源
* @param code 认证code
* @param auth_code 认证code,当使用支付宝登陆时,该值不为空。切勿修改该参数的命名!强迫症不要把他改成驼峰式命名哈~~~
* @param source 授权回调来源
* @param callback 回调参数包装类
* @return
*/
@RequestMapping("/callback/{source}")
public ModelAndView login(@PathVariable("source") String source, String code, String auth_code, HttpSession session) {
authService.login(source, code, auth_code);
public ModelAndView login(@PathVariable("source") String source, AuthCallback callback, HttpSession session) {
authService.login(source, callback);
String historyUrl = (String) session.getAttribute("historyUrl");
session.removeAttribute("historyUrl");
if (StringUtils.isEmpty(historyUrl)) {
......
......@@ -51,7 +51,7 @@
<aliyun.oss.version>2.8.3</aliyun.oss.version>
<oneblog.version>2.2.2</oneblog.version>
<blog-hunter.version>1.0.1</blog-hunter.version>
<justauth.version>1.5.1</justauth.version>
<justauth.version>1.10.0</justauth.version>
</properties>
<dependencyManagement>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册