1
0
mirror of https://gitee.com/bookshelfplus/bookshelfplus synced 2025-10-30 02:13:10 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee

第三方快捷登录前端按钮;后端跳转逻辑;数据库映射完成

This commit is contained in:
2022-04-03 23:40:03 +08:00
parent a54e96de38
commit f62bfed97f
16 changed files with 1326 additions and 9 deletions

View File

@@ -0,0 +1,38 @@
package plus.bookshelf.Common.ThirdParty;
import lombok.Data;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Component;
@Component
@ConfigurationProperties(prefix = "thirdparty")
@PropertySource("thirdparty.properties")
@Data
public class ThirdPartyConfig {
// Gitee
@Value("${thirdparty.gitee.clientid}")
private String giteeClientId;
@Value("${thirdparty.gitee.clientsecret}")
private String giteeClientsecret;
@Value("${thirdparty.gitee.redirecturi}")
private String giteeRedirecturi;
// QQ
@Value("${thirdparty.qq.clientid}")
private String qqClientid;
@Value("${thirdparty.qq.clientsecret}")
private String qqClientsecret;
@Value("${thirdparty.qq.redirecturi}")
private String qqRedirecturi;
//GitHub
@Value("${thirdparty.github.clientid}")
private String githubClientid;
@Value("${thirdparty.github.clientsecret}")
private String githubClientsecret;
@Value("${thirdparty.github.redirecturi}")
private String githubRedirecturi;
}

View File

@@ -0,0 +1,76 @@
package plus.bookshelf.Controller.Controller;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import me.zhyd.oauth.config.AuthConfig;
import me.zhyd.oauth.model.AuthCallback;
import me.zhyd.oauth.request.AuthGiteeRequest;
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.web.bind.annotation.*;
import plus.bookshelf.Common.Error.BusinessErrorCode;
import plus.bookshelf.Common.Error.BusinessException;
import plus.bookshelf.Common.Response.CommonReturnType;
import plus.bookshelf.Common.ThirdParty.ThirdPartyConfig;
import plus.bookshelf.Service.Impl.UserServiceImpl;
import java.util.Map;
@Api(tags = "第三方登录")
@Controller
@RequestMapping("/third-party")
public class ThirdPartyController extends BaseController {
// refer document: https://justauth.wiki/guide/
// Gitee: https://justauth.wiki/guide/oauth/gitee
// state在OAuth的流程中的主要作用就是保证请求完整性防止CSRF风险此处传的state将在回调时传回
@Autowired
private ThirdPartyConfig thirdPartyConfig;
@ApiOperation(value = "第三方用户登录跳转地址", notes = "传入需要登录的第三方平台大小写均可返回跳转url")
@RequestMapping(value = "login", method = {RequestMethod.GET})
@ResponseBody
public CommonReturnType login(@RequestParam(value = "platform") String platform) throws BusinessException {
AuthRequest authRequest = getAuthRequest(platform);
String authorizeUrl = authRequest.authorize(AuthStateUtils.createState());
return CommonReturnType.create(authorizeUrl);
}
@ApiOperation(value = "快捷登录回调函数", notes = "传入 code 值,进行登录")
@RequestMapping(value = "callback/{platform}", method = {RequestMethod.GET})
@ResponseBody
public CommonReturnType qq(@PathVariable("platform") String platform,
// @RequestParam Map<String,String> params,
AuthCallback callback) throws BusinessException {
// System.out.println(params);
// System.out.println(platform);
// System.out.println(params.get("code"));
// System.out.println(params.get("state"));
AuthRequest authRequest = getAuthRequest(platform);
return CommonReturnType.create(authRequest.login(callback));
}
// 创建授权request
private AuthRequest getAuthRequest(String platform) throws BusinessException {
switch (platform.toLowerCase()) {
case "gitee":
return new AuthGiteeRequest(AuthConfig.builder()
.clientId(thirdPartyConfig.getGiteeClientId())
.clientSecret(thirdPartyConfig.getGiteeClientsecret())
.redirectUri(thirdPartyConfig.getGiteeRedirecturi())
.build());
case "qq":
return new AuthGiteeRequest(AuthConfig.builder()
.clientId(thirdPartyConfig.getQqClientid())
.clientSecret(thirdPartyConfig.getQqClientsecret())
.redirectUri(thirdPartyConfig.getQqRedirecturi())
.build());
default:
throw new BusinessException(BusinessErrorCode.PARAMETER_VALIDATION_ERROR, "不支持该第三方平台");
}
}
}

View File

@@ -1,8 +1,6 @@
package plus.bookshelf.Controller.Controller;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.codec.digest.DigestUtils;
import org.springframework.beans.BeanUtils;
@@ -12,10 +10,7 @@ import org.springframework.web.bind.annotation.*;
import plus.bookshelf.Common.Error.BusinessErrorCode;
import plus.bookshelf.Common.Error.BusinessException;
import plus.bookshelf.Common.Response.CommonReturnType;
import plus.bookshelf.Common.SessionManager.LocalSessionManager;
import plus.bookshelf.Common.SessionManager.RedisSessionManager;
import plus.bookshelf.Controller.VO.UserVO;
import plus.bookshelf.Dao.Mapper.UserDOMapper;
import plus.bookshelf.Service.Impl.UserServiceImpl;
import plus.bookshelf.Service.Model.UserModel;

View File

@@ -0,0 +1,102 @@
package plus.bookshelf.Dao.DO;
public class ThirdPartyUserAuthDO {
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column third_party_user_auth_relation.id
*
* @mbg.generated
*/
private Integer id;
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column third_party_user_auth_relation.user_id
*
* @mbg.generated
*/
private String userId;
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column third_party_user_auth_relation.third_party_user_id
*
* @mbg.generated
*/
private String thirdPartyUserId;
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column third_party_user_auth_relation.id
*
* @return the value of third_party_user_auth_relation.id
*
* @mbg.generated
*/
public Integer getId() {
return id;
}
/**
* This method was generated by MyBatis Generator.
* This method sets the value of the database column third_party_user_auth_relation.id
*
* @param id the value for third_party_user_auth_relation.id
*
* @mbg.generated
*/
public void setId(Integer id) {
this.id = id;
}
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column third_party_user_auth_relation.user_id
*
* @return the value of third_party_user_auth_relation.user_id
*
* @mbg.generated
*/
public String getUserId() {
return userId;
}
/**
* This method was generated by MyBatis Generator.
* This method sets the value of the database column third_party_user_auth_relation.user_id
*
* @param userId the value for third_party_user_auth_relation.user_id
*
* @mbg.generated
*/
public void setUserId(String userId) {
this.userId = userId == null ? null : userId.trim();
}
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column third_party_user_auth_relation.third_party_user_id
*
* @return the value of third_party_user_auth_relation.third_party_user_id
*
* @mbg.generated
*/
public String getThirdPartyUserId() {
return thirdPartyUserId;
}
/**
* This method was generated by MyBatis Generator.
* This method sets the value of the database column third_party_user_auth_relation.third_party_user_id
*
* @param thirdPartyUserId the value for third_party_user_auth_relation.third_party_user_id
*
* @mbg.generated
*/
public void setThirdPartyUserId(String thirdPartyUserId) {
this.thirdPartyUserId = thirdPartyUserId == null ? null : thirdPartyUserId.trim();
}
}

View File

@@ -0,0 +1,597 @@
package plus.bookshelf.Dao.DO;
public class ThirdPartyUserDO {
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column third_party_user_info.id
*
* @mbg.generated
*/
private Integer id;
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column third_party_user_info.uuid
*
* @mbg.generated
*/
private String uuid;
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column third_party_user_info.source
*
* @mbg.generated
*/
private String source;
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column third_party_user_info.access_token
*
* @mbg.generated
*/
private String accessToken;
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column third_party_user_info.expire_in
*
* @mbg.generated
*/
private Integer expireIn;
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column third_party_user_info.refresh_token
*
* @mbg.generated
*/
private String refreshToken;
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column third_party_user_info.open_id
*
* @mbg.generated
*/
private String openId;
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column third_party_user_info.uid
*
* @mbg.generated
*/
private String uid;
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column third_party_user_info.access_code
*
* @mbg.generated
*/
private String accessCode;
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column third_party_user_info.union_id
*
* @mbg.generated
*/
private String unionId;
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column third_party_user_info.scope
*
* @mbg.generated
*/
private String scope;
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column third_party_user_info.token_type
*
* @mbg.generated
*/
private String tokenType;
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column third_party_user_info.id_token
*
* @mbg.generated
*/
private String idToken;
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column third_party_user_info.mac_algorithm
*
* @mbg.generated
*/
private String macAlgorithm;
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column third_party_user_info.mac_key
*
* @mbg.generated
*/
private String macKey;
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column third_party_user_info.code
*
* @mbg.generated
*/
private String code;
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column third_party_user_info.oauth_token
*
* @mbg.generated
*/
private String oauthToken;
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column third_party_user_info.oauth_token_secret
*
* @mbg.generated
*/
private String oauthTokenSecret;
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column third_party_user_info.id
*
* @return the value of third_party_user_info.id
*
* @mbg.generated
*/
public Integer getId() {
return id;
}
/**
* This method was generated by MyBatis Generator.
* This method sets the value of the database column third_party_user_info.id
*
* @param id the value for third_party_user_info.id
*
* @mbg.generated
*/
public void setId(Integer id) {
this.id = id;
}
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column third_party_user_info.uuid
*
* @return the value of third_party_user_info.uuid
*
* @mbg.generated
*/
public String getUuid() {
return uuid;
}
/**
* This method was generated by MyBatis Generator.
* This method sets the value of the database column third_party_user_info.uuid
*
* @param uuid the value for third_party_user_info.uuid
*
* @mbg.generated
*/
public void setUuid(String uuid) {
this.uuid = uuid == null ? null : uuid.trim();
}
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column third_party_user_info.source
*
* @return the value of third_party_user_info.source
*
* @mbg.generated
*/
public String getSource() {
return source;
}
/**
* This method was generated by MyBatis Generator.
* This method sets the value of the database column third_party_user_info.source
*
* @param source the value for third_party_user_info.source
*
* @mbg.generated
*/
public void setSource(String source) {
this.source = source == null ? null : source.trim();
}
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column third_party_user_info.access_token
*
* @return the value of third_party_user_info.access_token
*
* @mbg.generated
*/
public String getAccessToken() {
return accessToken;
}
/**
* This method was generated by MyBatis Generator.
* This method sets the value of the database column third_party_user_info.access_token
*
* @param accessToken the value for third_party_user_info.access_token
*
* @mbg.generated
*/
public void setAccessToken(String accessToken) {
this.accessToken = accessToken == null ? null : accessToken.trim();
}
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column third_party_user_info.expire_in
*
* @return the value of third_party_user_info.expire_in
*
* @mbg.generated
*/
public Integer getExpireIn() {
return expireIn;
}
/**
* This method was generated by MyBatis Generator.
* This method sets the value of the database column third_party_user_info.expire_in
*
* @param expireIn the value for third_party_user_info.expire_in
*
* @mbg.generated
*/
public void setExpireIn(Integer expireIn) {
this.expireIn = expireIn;
}
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column third_party_user_info.refresh_token
*
* @return the value of third_party_user_info.refresh_token
*
* @mbg.generated
*/
public String getRefreshToken() {
return refreshToken;
}
/**
* This method was generated by MyBatis Generator.
* This method sets the value of the database column third_party_user_info.refresh_token
*
* @param refreshToken the value for third_party_user_info.refresh_token
*
* @mbg.generated
*/
public void setRefreshToken(String refreshToken) {
this.refreshToken = refreshToken == null ? null : refreshToken.trim();
}
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column third_party_user_info.open_id
*
* @return the value of third_party_user_info.open_id
*
* @mbg.generated
*/
public String getOpenId() {
return openId;
}
/**
* This method was generated by MyBatis Generator.
* This method sets the value of the database column third_party_user_info.open_id
*
* @param openId the value for third_party_user_info.open_id
*
* @mbg.generated
*/
public void setOpenId(String openId) {
this.openId = openId == null ? null : openId.trim();
}
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column third_party_user_info.uid
*
* @return the value of third_party_user_info.uid
*
* @mbg.generated
*/
public String getUid() {
return uid;
}
/**
* This method was generated by MyBatis Generator.
* This method sets the value of the database column third_party_user_info.uid
*
* @param uid the value for third_party_user_info.uid
*
* @mbg.generated
*/
public void setUid(String uid) {
this.uid = uid == null ? null : uid.trim();
}
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column third_party_user_info.access_code
*
* @return the value of third_party_user_info.access_code
*
* @mbg.generated
*/
public String getAccessCode() {
return accessCode;
}
/**
* This method was generated by MyBatis Generator.
* This method sets the value of the database column third_party_user_info.access_code
*
* @param accessCode the value for third_party_user_info.access_code
*
* @mbg.generated
*/
public void setAccessCode(String accessCode) {
this.accessCode = accessCode == null ? null : accessCode.trim();
}
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column third_party_user_info.union_id
*
* @return the value of third_party_user_info.union_id
*
* @mbg.generated
*/
public String getUnionId() {
return unionId;
}
/**
* This method was generated by MyBatis Generator.
* This method sets the value of the database column third_party_user_info.union_id
*
* @param unionId the value for third_party_user_info.union_id
*
* @mbg.generated
*/
public void setUnionId(String unionId) {
this.unionId = unionId == null ? null : unionId.trim();
}
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column third_party_user_info.scope
*
* @return the value of third_party_user_info.scope
*
* @mbg.generated
*/
public String getScope() {
return scope;
}
/**
* This method was generated by MyBatis Generator.
* This method sets the value of the database column third_party_user_info.scope
*
* @param scope the value for third_party_user_info.scope
*
* @mbg.generated
*/
public void setScope(String scope) {
this.scope = scope == null ? null : scope.trim();
}
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column third_party_user_info.token_type
*
* @return the value of third_party_user_info.token_type
*
* @mbg.generated
*/
public String getTokenType() {
return tokenType;
}
/**
* This method was generated by MyBatis Generator.
* This method sets the value of the database column third_party_user_info.token_type
*
* @param tokenType the value for third_party_user_info.token_type
*
* @mbg.generated
*/
public void setTokenType(String tokenType) {
this.tokenType = tokenType == null ? null : tokenType.trim();
}
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column third_party_user_info.id_token
*
* @return the value of third_party_user_info.id_token
*
* @mbg.generated
*/
public String getIdToken() {
return idToken;
}
/**
* This method was generated by MyBatis Generator.
* This method sets the value of the database column third_party_user_info.id_token
*
* @param idToken the value for third_party_user_info.id_token
*
* @mbg.generated
*/
public void setIdToken(String idToken) {
this.idToken = idToken == null ? null : idToken.trim();
}
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column third_party_user_info.mac_algorithm
*
* @return the value of third_party_user_info.mac_algorithm
*
* @mbg.generated
*/
public String getMacAlgorithm() {
return macAlgorithm;
}
/**
* This method was generated by MyBatis Generator.
* This method sets the value of the database column third_party_user_info.mac_algorithm
*
* @param macAlgorithm the value for third_party_user_info.mac_algorithm
*
* @mbg.generated
*/
public void setMacAlgorithm(String macAlgorithm) {
this.macAlgorithm = macAlgorithm == null ? null : macAlgorithm.trim();
}
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column third_party_user_info.mac_key
*
* @return the value of third_party_user_info.mac_key
*
* @mbg.generated
*/
public String getMacKey() {
return macKey;
}
/**
* This method was generated by MyBatis Generator.
* This method sets the value of the database column third_party_user_info.mac_key
*
* @param macKey the value for third_party_user_info.mac_key
*
* @mbg.generated
*/
public void setMacKey(String macKey) {
this.macKey = macKey == null ? null : macKey.trim();
}
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column third_party_user_info.code
*
* @return the value of third_party_user_info.code
*
* @mbg.generated
*/
public String getCode() {
return code;
}
/**
* This method was generated by MyBatis Generator.
* This method sets the value of the database column third_party_user_info.code
*
* @param code the value for third_party_user_info.code
*
* @mbg.generated
*/
public void setCode(String code) {
this.code = code == null ? null : code.trim();
}
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column third_party_user_info.oauth_token
*
* @return the value of third_party_user_info.oauth_token
*
* @mbg.generated
*/
public String getOauthToken() {
return oauthToken;
}
/**
* This method was generated by MyBatis Generator.
* This method sets the value of the database column third_party_user_info.oauth_token
*
* @param oauthToken the value for third_party_user_info.oauth_token
*
* @mbg.generated
*/
public void setOauthToken(String oauthToken) {
this.oauthToken = oauthToken == null ? null : oauthToken.trim();
}
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column third_party_user_info.oauth_token_secret
*
* @return the value of third_party_user_info.oauth_token_secret
*
* @mbg.generated
*/
public String getOauthTokenSecret() {
return oauthTokenSecret;
}
/**
* This method was generated by MyBatis Generator.
* This method sets the value of the database column third_party_user_info.oauth_token_secret
*
* @param oauthTokenSecret the value for third_party_user_info.oauth_token_secret
*
* @mbg.generated
*/
public void setOauthTokenSecret(String oauthTokenSecret) {
this.oauthTokenSecret = oauthTokenSecret == null ? null : oauthTokenSecret.trim();
}
}

View File

@@ -0,0 +1,21 @@
package plus.bookshelf.Dao.Mapper;
import plus.bookshelf.Dao.DO.ThirdPartyUserAuthDO;
public interface ThirdPartyUserAuthDOMapper {
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table third_party_user_auth_relation
*
* @mbg.generated
*/
int insert(ThirdPartyUserAuthDO record);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table third_party_user_auth_relation
*
* @mbg.generated
*/
int insertSelective(ThirdPartyUserAuthDO record);
}

View File

@@ -0,0 +1,53 @@
package plus.bookshelf.Dao.Mapper;
import plus.bookshelf.Dao.DO.ThirdPartyUserDO;
public interface ThirdPartyUserDOMapper {
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table third_party_user_info
*
* @mbg.generated
*/
int deleteByPrimaryKey(Integer id);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table third_party_user_info
*
* @mbg.generated
*/
int insert(ThirdPartyUserDO record);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table third_party_user_info
*
* @mbg.generated
*/
int insertSelective(ThirdPartyUserDO record);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table third_party_user_info
*
* @mbg.generated
*/
ThirdPartyUserDO selectByPrimaryKey(Integer id);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table third_party_user_info
*
* @mbg.generated
*/
int updateByPrimaryKeySelective(ThirdPartyUserDO record);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table third_party_user_info
*
* @mbg.generated
*/
int updateByPrimaryKey(ThirdPartyUserDO record);
}