mrbird 6 лет назад
Родитель
Сommit
4feb4311f7

+ 1 - 1
febs-auth/src/main/java/cc/mrbird/febs/auth/controller/SocialLoginController.java

@@ -2,7 +2,7 @@ package cc.mrbird.febs.auth.controller;
 
 import cc.mrbird.febs.auth.entity.BindUser;
 import cc.mrbird.febs.auth.entity.UserConnection;
-import cc.mrbird.febs.auth.service.impl.SocialLoginService;
+import cc.mrbird.febs.auth.service.SocialLoginService;
 import cc.mrbird.febs.common.entity.FebsResponse;
 import cc.mrbird.febs.common.exception.FebsException;
 import cc.mrbird.febs.common.utils.FebsUtil;

+ 90 - 0
febs-auth/src/main/java/cc/mrbird/febs/auth/service/SocialLoginService.java

@@ -0,0 +1,90 @@
+package cc.mrbird.febs.auth.service;
+
+import cc.mrbird.febs.auth.entity.BindUser;
+import cc.mrbird.febs.auth.entity.UserConnection;
+import cc.mrbird.febs.common.entity.FebsResponse;
+import cc.mrbird.febs.common.exception.FebsException;
+import me.zhyd.oauth.model.AuthCallback;
+import me.zhyd.oauth.model.AuthUser;
+import me.zhyd.oauth.request.AuthRequest;
+import org.springframework.security.oauth2.common.OAuth2AccessToken;
+
+import java.util.List;
+
+public interface SocialLoginService {
+
+    /**
+     * 解析第三方登录请求
+     *
+     * @param oauthType 第三方平台类型
+     * @return AuthRequest
+     * @throws FebsException 异常
+     */
+    AuthRequest renderAuth(String oauthType) throws FebsException;
+
+    /**
+     * 处理第三方登录(绑定页面)
+     *
+     * @param oauthType 第三方平台类型
+     * @param callback  回调
+     * @return FebsResponse
+     * @throws FebsException 异常
+     */
+    FebsResponse resolveBind(String oauthType, AuthCallback callback) throws FebsException;
+
+    /**
+     * 处理第三方登录(登录页面)
+     *
+     * @param oauthType 第三方平台类型
+     * @param callback  回调
+     * @return FebsResponse
+     * @throws FebsException 异常
+     */
+    FebsResponse resolveLogin(String oauthType, AuthCallback callback) throws FebsException;
+
+    /**
+     * 绑定并登录
+     *
+     * @param bindUser 绑定用户
+     * @param authUser 第三方平台对象
+     * @return OAuth2AccessToken 令牌对象
+     * @throws FebsException 异常
+     */
+    OAuth2AccessToken bindLogin(BindUser bindUser, AuthUser authUser) throws FebsException;
+
+    /**
+     * 注册并登录
+     *
+     * @param registUser 注册用户
+     * @param authUser   第三方平台对象
+     * @return OAuth2AccessToken 令牌对象
+     * @throws FebsException 异常
+     */
+    OAuth2AccessToken signLogin(BindUser registUser, AuthUser authUser) throws FebsException;
+
+    /**
+     * 绑定
+     *
+     * @param bindUser 绑定对象
+     * @param authUser 第三方平台对象
+     * @throws FebsException 异常
+     */
+    void bind(BindUser bindUser, AuthUser authUser) throws FebsException;
+
+    /**
+     * 解绑
+     *
+     * @param bindUser  绑定对象
+     * @param oauthType 第三方平台对象
+     * @throws FebsException 异常
+     */
+    void unbind(BindUser bindUser, String oauthType) throws FebsException;
+
+    /**
+     * 根据用户名获取绑定关系
+     *
+     * @param username 用户名
+     * @return 绑定关系集合
+     */
+    List<UserConnection> findUserConnections(String username);
+}

+ 10 - 1
febs-auth/src/main/java/cc/mrbird/febs/auth/service/impl/SocialLoginService.java → febs-auth/src/main/java/cc/mrbird/febs/auth/service/impl/SocialLoginServiceImpl.java

@@ -4,6 +4,7 @@ import cc.mrbird.febs.auth.entity.BindUser;
 import cc.mrbird.febs.auth.entity.UserConnection;
 import cc.mrbird.febs.auth.manager.UserManager;
 import cc.mrbird.febs.auth.properties.FebsAuthProperties;
+import cc.mrbird.febs.auth.service.SocialLoginService;
 import cc.mrbird.febs.auth.service.UserConnectionService;
 import cc.mrbird.febs.common.entity.FebsAuthUser;
 import cc.mrbird.febs.common.entity.FebsResponse;
@@ -40,7 +41,7 @@ import java.util.Map;
  * @author MrBird
  */
 @Service
-public class SocialLoginService {
+public class SocialLoginServiceImpl implements SocialLoginService {
 
     private static final String USERNAME = "username";
     private static final String PASSWORD = "password";
@@ -63,10 +64,12 @@ public class SocialLoginService {
     @Autowired
     private RedisClientDetailsService redisClientDetailsService;
 
+    @Override
     public AuthRequest renderAuth(String oauthType) throws FebsException {
         return factory.get(getAuthSource(oauthType));
     }
 
+    @Override
     public FebsResponse resolveBind(String oauthType, AuthCallback callback) throws FebsException {
         FebsResponse febsResponse = new FebsResponse();
         AuthRequest authRequest = factory.get(getAuthSource(oauthType));
@@ -79,6 +82,7 @@ public class SocialLoginService {
         return febsResponse;
     }
 
+    @Override
     public FebsResponse resolveLogin(String oauthType, AuthCallback callback) throws FebsException {
         FebsResponse febsResponse = new FebsResponse();
         AuthRequest authRequest = factory.get(getAuthSource(oauthType));
@@ -103,6 +107,7 @@ public class SocialLoginService {
         return febsResponse;
     }
 
+    @Override
     public OAuth2AccessToken bindLogin(BindUser bindUser, AuthUser authUser) throws FebsException {
         SystemUser systemUser = userManager.findByName(bindUser.getBindUsername());
         if (systemUser == null || !passwordEncoder.matches(bindUser.getBindPassword(), systemUser.getPassword())) {
@@ -112,6 +117,7 @@ public class SocialLoginService {
         return this.getOAuth2AccessToken(systemUser);
     }
 
+    @Override
     public OAuth2AccessToken signLogin(BindUser registUser, AuthUser authUser) throws FebsException {
         SystemUser user = this.userManager.findByName(registUser.getBindUsername());
         if (user != null) {
@@ -123,6 +129,7 @@ public class SocialLoginService {
         return this.getOAuth2AccessToken(systemUser);
     }
 
+    @Override
     public void bind(BindUser bindUser, AuthUser authUser) throws FebsException {
         String username = bindUser.getBindUsername();
         if (isCurrentUser(username)) {
@@ -138,6 +145,7 @@ public class SocialLoginService {
         }
     }
 
+    @Override
     public void unbind(BindUser bindUser, String oauthType) throws FebsException {
         String username = bindUser.getBindUsername();
         if (isCurrentUser(username)) {
@@ -147,6 +155,7 @@ public class SocialLoginService {
         }
     }
 
+    @Override
     public List<UserConnection> findUserConnections(String username) {
         return this.userConnectionService.selectByCondition(username);
     }

+ 0 - 1
febs-auth/src/main/resources/templates/result.html

@@ -12,7 +12,6 @@
 <script th:inline="javascript">
     var response = [[${response}]];
     var frontUrl = [[${frontUrl}]];
-    console.log(frontUrl);
     window.onload = function () {
         window.opener.postMessage(response, frontUrl);
         window.close();