提交 4f272348 编写于 作者: 智布道's avatar 智布道 👁

从UrlBuilder中拆分github、google、linkedin和microsoft相关的URL

上级 ec31b7cb
......@@ -10,8 +10,11 @@ import me.zhyd.oauth.model.AuthCallback;
import me.zhyd.oauth.model.AuthToken;
import me.zhyd.oauth.model.AuthUser;
import me.zhyd.oauth.model.AuthUserGender;
import me.zhyd.oauth.url.GithubUrlBuilder;
import me.zhyd.oauth.url.entity.AuthAccessTokenEntity;
import me.zhyd.oauth.url.entity.AuthAuthorizeEntity;
import me.zhyd.oauth.url.entity.AuthUserInfoEntity;
import me.zhyd.oauth.utils.GlobalAuthUtil;
import me.zhyd.oauth.utils.UrlBuilder;
import java.util.Map;
......@@ -25,12 +28,15 @@ import java.util.Map;
public class AuthGithubRequest extends BaseAuthRequest {
public AuthGithubRequest(AuthConfig config) {
super(config, AuthSource.GITHUB);
super(config, AuthSource.GITHUB, new GithubUrlBuilder());
}
@Override
protected AuthToken getAccessToken(AuthCallback authCallback) {
String accessTokenUrl = UrlBuilder.getGithubAccessTokenUrl(config.getClientId(), config.getClientSecret(), authCallback.getCode(), config.getRedirectUri());
String accessTokenUrl = this.urlBuilder.getAccessTokenUrl(AuthAccessTokenEntity.builder()
.config(config)
.code(authCallback.getCode())
.build());
HttpResponse response = HttpRequest.post(accessTokenUrl).execute();
Map<String, String> res = GlobalAuthUtil.parseStringToMap(response.body());
if (res.containsKey("error")) {
......@@ -42,7 +48,9 @@ public class AuthGithubRequest extends BaseAuthRequest {
@Override
protected AuthUser getUserInfo(AuthToken authToken) {
String accessToken = authToken.getAccessToken();
HttpResponse response = HttpRequest.get(UrlBuilder.getGithubUserInfoUrl(accessToken)).execute();
HttpResponse response = HttpRequest.get(this.urlBuilder.getUserInfoUrl(AuthUserInfoEntity.builder()
.accessToken(accessToken)
.build())).execute();
String userInfo = response.body();
JSONObject object = JSONObject.parseObject(userInfo);
return AuthUser.builder()
......@@ -68,6 +76,8 @@ public class AuthGithubRequest extends BaseAuthRequest {
*/
@Override
public String authorize() {
return UrlBuilder.getGithubAuthorizeUrl(config.getClientId(), config.getRedirectUri(), config.getState());
return this.urlBuilder.getAuthorizeUrl(AuthAuthorizeEntity.builder()
.config(config)
.build());
}
}
......@@ -10,7 +10,10 @@ import me.zhyd.oauth.model.AuthCallback;
import me.zhyd.oauth.model.AuthToken;
import me.zhyd.oauth.model.AuthUser;
import me.zhyd.oauth.model.AuthUserGender;
import me.zhyd.oauth.utils.UrlBuilder;
import me.zhyd.oauth.url.GoogleUrlBuilder;
import me.zhyd.oauth.url.entity.AuthAccessTokenEntity;
import me.zhyd.oauth.url.entity.AuthAuthorizeEntity;
import me.zhyd.oauth.url.entity.AuthUserInfoEntity;
/**
* Google登录
......@@ -22,13 +25,15 @@ import me.zhyd.oauth.utils.UrlBuilder;
public class AuthGoogleRequest extends BaseAuthRequest {
public AuthGoogleRequest(AuthConfig config) {
super(config, AuthSource.GOOGLE);
super(config, AuthSource.GOOGLE, new GoogleUrlBuilder());
}
@Override
protected AuthToken getAccessToken(AuthCallback authCallback) {
String accessTokenUrl = UrlBuilder.getGoogleAccessTokenUrl(config.getClientId(), config.getClientSecret(), authCallback.getCode(), config
.getRedirectUri());
String accessTokenUrl = this.urlBuilder.getAccessTokenUrl(AuthAccessTokenEntity.builder()
.config(config)
.code(authCallback.getCode())
.build());
HttpResponse response = HttpRequest.post(accessTokenUrl).execute();
JSONObject accessTokenObject = JSONObject.parseObject(response.body());
......@@ -49,7 +54,9 @@ public class AuthGoogleRequest extends BaseAuthRequest {
@Override
protected AuthUser getUserInfo(AuthToken authToken) {
String accessToken = authToken.getIdToken();
HttpResponse response = HttpRequest.get(UrlBuilder.getGoogleUserInfoUrl(accessToken)).execute();
HttpResponse response = HttpRequest.get(this.urlBuilder.getUserInfoUrl(AuthUserInfoEntity.builder()
.accessToken(accessToken)
.build())).execute();
String userInfo = response.body();
JSONObject object = JSONObject.parseObject(userInfo);
return AuthUser.builder()
......@@ -72,6 +79,8 @@ public class AuthGoogleRequest extends BaseAuthRequest {
*/
@Override
public String authorize() {
return UrlBuilder.getGoogleAuthorizeUrl(config.getClientId(), config.getRedirectUri(), config.getState());
return this.urlBuilder.getAuthorizeUrl(AuthAuthorizeEntity.builder()
.config(config)
.build());
}
}
......@@ -8,8 +8,12 @@ import me.zhyd.oauth.config.AuthConfig;
import me.zhyd.oauth.config.AuthSource;
import me.zhyd.oauth.exception.AuthException;
import me.zhyd.oauth.model.*;
import me.zhyd.oauth.url.LinkedinUrlBuilder;
import me.zhyd.oauth.url.entity.AuthAccessTokenEntity;
import me.zhyd.oauth.url.entity.AuthAuthorizeEntity;
import me.zhyd.oauth.url.entity.AuthRefreshTokenEntity;
import me.zhyd.oauth.url.entity.AuthUserInfoEntity;
import me.zhyd.oauth.utils.StringUtils;
import me.zhyd.oauth.utils.UrlBuilder;
/**
......@@ -22,20 +26,22 @@ import me.zhyd.oauth.utils.UrlBuilder;
public class AuthLinkedinRequest extends BaseAuthRequest {
public AuthLinkedinRequest(AuthConfig config) {
super(config, AuthSource.LINKEDIN);
super(config, AuthSource.LINKEDIN, new LinkedinUrlBuilder());
}
@Override
protected AuthToken getAccessToken(AuthCallback authCallback) {
String accessTokenUrl = UrlBuilder.getLinkedinAccessTokenUrl(config.getClientId(), config.getClientSecret(), authCallback.getCode(), config
.getRedirectUri());
String accessTokenUrl = this.urlBuilder.getAccessTokenUrl(AuthAccessTokenEntity.builder()
.config(config)
.code(authCallback.getCode())
.build());
return this.getToken(accessTokenUrl);
}
@Override
protected AuthUser getUserInfo(AuthToken authToken) {
String accessToken = authToken.getAccessToken();
HttpResponse response = HttpRequest.get(UrlBuilder.getLinkedinUserInfoUrl())
HttpResponse response = HttpRequest.get(this.urlBuilder.getUserInfoUrl(AuthUserInfoEntity.builder().build()))
.header("Host", "api.linkedin.com")
.header("Connection", "Keep-Alive")
.header("Authorization", "Bearer " + accessToken)
......@@ -93,7 +99,9 @@ public class AuthLinkedinRequest extends BaseAuthRequest {
*/
@Override
public String authorize() {
return UrlBuilder.getLinkedinAuthorizeUrl(config.getClientId(), config.getRedirectUri(), config.getState());
return this.urlBuilder.getAuthorizeUrl(AuthAuthorizeEntity.builder()
.config(config)
.build());
}
private String getUserEmail(String accessToken) {
......@@ -128,8 +136,10 @@ public class AuthLinkedinRequest extends BaseAuthRequest {
if (StringUtils.isEmpty(oldToken.getRefreshToken())) {
throw new AuthException(ResponseStatus.UNSUPPORTED);
}
String refreshTokenUrl = UrlBuilder.getLinkedinRefreshUrl(config.getClientId(), config.getClientSecret(), oldToken
.getRefreshToken());
String refreshTokenUrl = this.urlBuilder.getRefreshUrl(AuthRefreshTokenEntity.builder()
.config(config)
.refreshToken(oldToken.getRefreshToken())
.build());
return AuthResponse.builder()
.code(ResponseStatus.SUCCESS.getCode())
.data(this.getToken(refreshTokenUrl))
......
......@@ -8,6 +8,7 @@ import me.zhyd.oauth.config.AuthConfig;
import me.zhyd.oauth.config.AuthSource;
import me.zhyd.oauth.exception.AuthException;
import me.zhyd.oauth.model.*;
import me.zhyd.oauth.url.MiUrlBuilder;
import me.zhyd.oauth.url.entity.AuthAccessTokenEntity;
import me.zhyd.oauth.url.entity.AuthAuthorizeEntity;
import me.zhyd.oauth.url.entity.AuthRefreshTokenEntity;
......@@ -26,7 +27,7 @@ public class AuthMiRequest extends BaseAuthRequest {
private static final String PREFIX = "&&&START&&&";
public AuthMiRequest(AuthConfig config) {
super(config, AuthSource.MI);
super(config, AuthSource.MI, new MiUrlBuilder());
}
@Override
......
......@@ -8,7 +8,11 @@ import me.zhyd.oauth.config.AuthConfig;
import me.zhyd.oauth.config.AuthSource;
import me.zhyd.oauth.exception.AuthException;
import me.zhyd.oauth.model.*;
import me.zhyd.oauth.utils.UrlBuilder;
import me.zhyd.oauth.url.MicrosoftUrlBuilder;
import me.zhyd.oauth.url.entity.AuthAccessTokenEntity;
import me.zhyd.oauth.url.entity.AuthAuthorizeEntity;
import me.zhyd.oauth.url.entity.AuthRefreshTokenEntity;
import me.zhyd.oauth.url.entity.AuthUserInfoEntity;
import java.util.HashMap;
import java.util.Map;
......@@ -22,13 +26,15 @@ import java.util.Map;
*/
public class AuthMicrosoftRequest extends BaseAuthRequest {
public AuthMicrosoftRequest(AuthConfig config) {
super(config, AuthSource.MICROSOFT);
super(config, AuthSource.MICROSOFT, new MicrosoftUrlBuilder());
}
@Override
protected AuthToken getAccessToken(AuthCallback authCallback) {
String accessTokenUrl = UrlBuilder.getMicrosoftAccessTokenUrl(config.getClientId(), config.getClientSecret(), config
.getRedirectUri(), authCallback.getCode());
String accessTokenUrl = this.urlBuilder.getAccessTokenUrl(AuthAccessTokenEntity.builder()
.config(config)
.code(authCallback.getCode())
.build());
return getToken(accessTokenUrl);
}
......@@ -72,7 +78,7 @@ public class AuthMicrosoftRequest extends BaseAuthRequest {
String token = authToken.getAccessToken();
String tokenType = authToken.getTokenType();
String jwt = tokenType + " " + token;
HttpResponse response = HttpRequest.get(UrlBuilder.getMicrosoftUserInfoUrl())
HttpResponse response = HttpRequest.get(this.urlBuilder.getUserInfoUrl(AuthUserInfoEntity.builder().build()))
.header("Authorization", jwt)
.execute();
String userInfo = response.body();
......@@ -96,7 +102,9 @@ public class AuthMicrosoftRequest extends BaseAuthRequest {
*/
@Override
public String authorize() {
return UrlBuilder.getMicrosoftAuthorizeUrl(config.getClientId(), config.getRedirectUri(), config.getState());
return this.urlBuilder.getAuthorizeUrl(AuthAuthorizeEntity.builder()
.config(config)
.build());
}
/**
......@@ -107,8 +115,10 @@ public class AuthMicrosoftRequest extends BaseAuthRequest {
*/
@Override
public AuthResponse refresh(AuthToken authToken) {
String refreshTokenUrl = UrlBuilder.getMicrosoftRefreshUrl(config.getClientId(), config.getClientSecret(), config
.getRedirectUri(), authToken.getRefreshToken());
String refreshTokenUrl = this.urlBuilder.getRefreshUrl(AuthRefreshTokenEntity.builder()
.config(config)
.refreshToken(authToken.getRefreshToken())
.build());
return AuthResponse.builder().code(ResponseStatus.SUCCESS.getCode()).data(getToken(refreshTokenUrl)).build();
}
......
package me.zhyd.oauth.url;
import me.zhyd.oauth.config.AuthConfig;
import me.zhyd.oauth.config.AuthSource;
import me.zhyd.oauth.url.entity.*;
import java.text.MessageFormat;
/**
* Github相关的URL构建类
*
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
* @version 1.0
* @since 1.8
*/
public class GithubUrlBuilder extends AbstractUrlBuilder {
private static final String GITHUB_ACCESS_TOKEN_PATTERN = "{0}?client_id={1}&client_secret={2}&code={3}&redirect_uri={4}";
private static final String GITHUB_USER_INFO_PATTERN = "{0}?access_token={1}";
private static final String GITHUB_AUTHORIZE_PATTERN = "{0}?client_id={1}&redirect_uri={2}&state={3}";
@Override
public String getAccessTokenUrl(AuthAccessTokenEntity accessTokenEntity) {
AuthConfig config = accessTokenEntity.getConfig();
return MessageFormat.format(GITHUB_ACCESS_TOKEN_PATTERN, AuthSource.GITHUB.accessToken(), config.getClientId(), config.getClientSecret(), accessTokenEntity.getCode(), config.getRedirectUri());
}
@Override
public String getUserInfoUrl(AuthUserInfoEntity userInfoEntity) {
return MessageFormat.format(GITHUB_USER_INFO_PATTERN, AuthSource.GITHUB.userInfo(), userInfoEntity.getAccessToken());
}
@Override
public String getAuthorizeUrl(AuthAuthorizeEntity authorizeEntity) {
AuthConfig config = authorizeEntity.getConfig();
return MessageFormat.format(GITHUB_AUTHORIZE_PATTERN, AuthSource.GITHUB.authorize(), config.getClientId(), config.getRedirectUri(), this.getRealState(config.getState()));
}
@Override
public String getRefreshUrl(AuthRefreshTokenEntity refreshTokenEntity) {
return null;
}
@Override
public String getRevokeUrl(AuthRevokeEntity revokeEntity) {
return null;
}
}
package me.zhyd.oauth.url;
import me.zhyd.oauth.config.AuthConfig;
import me.zhyd.oauth.config.AuthSource;
import me.zhyd.oauth.url.entity.*;
import java.text.MessageFormat;
/**
* Google相关的URL构建类
*
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
* @version 1.0
* @since 1.8
*/
public class GoogleUrlBuilder extends AbstractUrlBuilder {
private static final String GOOGLE_AUTHORIZE_PATTERN = "{0}?client_id={1}&response_type=code&scope=openid%20email%20profile&redirect_uri={2}&state={3}";
private static final String GOOGLE_ACCESS_TOKEN_PATTERN = "{0}?client_id={1}&client_secret={2}&code={3}&redirect_uri={4}&grant_type=authorization_code";
private static final String GOOGLE_USER_INFO_PATTERN = "{0}?id_token={1}";
@Override
public String getAccessTokenUrl(AuthAccessTokenEntity accessTokenEntity) {
AuthConfig config = accessTokenEntity.getConfig();
return MessageFormat.format(GOOGLE_ACCESS_TOKEN_PATTERN, AuthSource.GOOGLE.accessToken(), config.getClientId(), config.getClientSecret(), accessTokenEntity.getCode(), config.getRedirectUri());
}
@Override
public String getUserInfoUrl(AuthUserInfoEntity userInfoEntity) {
return MessageFormat.format(GOOGLE_USER_INFO_PATTERN, AuthSource.GOOGLE.userInfo(), userInfoEntity.getAccessToken());
}
@Override
public String getAuthorizeUrl(AuthAuthorizeEntity authorizeEntity) {
AuthConfig config = authorizeEntity.getConfig();
return MessageFormat.format(GOOGLE_AUTHORIZE_PATTERN, AuthSource.GOOGLE.authorize(), config.getClientId(), config.getRedirectUri(), this.getRealState(config.getState()));
}
@Override
public String getRefreshUrl(AuthRefreshTokenEntity refreshTokenEntity) {
return null;
}
@Override
public String getRevokeUrl(AuthRevokeEntity revokeEntity) {
return null;
}
}
package me.zhyd.oauth.url;
import me.zhyd.oauth.config.AuthConfig;
import me.zhyd.oauth.config.AuthSource;
import me.zhyd.oauth.url.entity.*;
import java.text.MessageFormat;
/**
* Microsoft相关的URL构建类
*
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
* @version 1.0
* @since 1.8
*/
public class LinkedinUrlBuilder extends AbstractUrlBuilder {
private static final String LINKEDIN_AUTHORIZE_PATTERN = "{0}?client_id={1}&redirect_uri={2}&state={3}&response_type=code&scope=r_liteprofile%20r_emailaddress%20w_member_social";
private static final String LINKEDIN_ACCESS_TOKEN_PATTERN = "{0}?client_id={1}&client_secret={2}&code={3}&redirect_uri={4}&grant_type=authorization_code";
private static final String LINKEDIN_USER_INFO_PATTERN = "{0}?projection=(id,firstName,lastName,profilePicture(displayImage~:playableStreams))";
private static final String LINKEDIN_REFRESH_TOKEN_PATTERN = "{0}?client_id={1}&client_secret={2}&refresh_token={3}&grant_type=refresh_token";
@Override
public String getAccessTokenUrl(AuthAccessTokenEntity accessTokenEntity) {
AuthConfig config = accessTokenEntity.getConfig();
return MessageFormat.format(LINKEDIN_ACCESS_TOKEN_PATTERN, AuthSource.LINKEDIN.accessToken(), config.getClientId(), config.getClientSecret(), accessTokenEntity.getCode(), config.getRedirectUri());
}
@Override
public String getUserInfoUrl(AuthUserInfoEntity userInfoEntity) {
return MessageFormat.format(LINKEDIN_USER_INFO_PATTERN, AuthSource.LINKEDIN.userInfo());
}
@Override
public String getAuthorizeUrl(AuthAuthorizeEntity authorizeEntity) {
AuthConfig config = authorizeEntity.getConfig();
return MessageFormat.format(LINKEDIN_AUTHORIZE_PATTERN, AuthSource.LINKEDIN.authorize(), config.getClientId(), config.getRedirectUri(), this.getRealState(config.getState()));
}
@Override
public String getRefreshUrl(AuthRefreshTokenEntity refreshTokenEntity) {
AuthConfig config = refreshTokenEntity.getConfig();
return MessageFormat.format(LINKEDIN_REFRESH_TOKEN_PATTERN, AuthSource.LINKEDIN.refresh(), config.getClientId(), config.getClientSecret(), refreshTokenEntity.getRefreshToken());
}
@Override
public String getRevokeUrl(AuthRevokeEntity revokeEntity) {
return null;
}
}
package me.zhyd.oauth.url;
import me.zhyd.oauth.config.AuthConfig;
import me.zhyd.oauth.config.AuthSource;
import me.zhyd.oauth.url.entity.*;
import java.text.MessageFormat;
/**
* Microsoft相关的URL构建类
*
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
* @version 1.0
* @since 1.8
*/
public class MicrosoftUrlBuilder extends AbstractUrlBuilder {
private static final String MICROSOFT_AUTHORIZE_PATTERN = "{0}?client_id={1}&response_type=code&redirect_uri={2}&response_mode=query&scope=offline_access%20user.read%20mail.read&state={3}";
private static final String MICROSOFT_ACCESS_TOKEN_PATTERN = "{0}?client_id={1}&client_secret={2}&scope=user.read%20mail.read&redirect_uri={3}&code={4}&grant_type=authorization_code";
private static final String MICROSOFT_USER_INFO_PATTERN = "{0}";
private static final String MICROSOFT_REFRESH_TOKEN_PATTERN = "{0}?client_id={1}&client_secret={2}&scope=user.read%20mail.read&redirect_uri={3}&refresh_token={4}&grant_type=refresh_token";
@Override
public String getAccessTokenUrl(AuthAccessTokenEntity accessTokenEntity) {
AuthConfig config = accessTokenEntity.getConfig();
return MessageFormat.format(MICROSOFT_ACCESS_TOKEN_PATTERN, AuthSource.MICROSOFT.accessToken(), config.getClientId(), config.getClientSecret(), config.getRedirectUri(), accessTokenEntity.getCode());
}
@Override
public String getUserInfoUrl(AuthUserInfoEntity userInfoEntity) {
return MessageFormat.format(MICROSOFT_USER_INFO_PATTERN, AuthSource.MICROSOFT.userInfo());
}
@Override
public String getAuthorizeUrl(AuthAuthorizeEntity authorizeEntity) {
AuthConfig config = authorizeEntity.getConfig();
return MessageFormat.format(MICROSOFT_AUTHORIZE_PATTERN, AuthSource.MICROSOFT.authorize(), config.getClientId(), config.getRedirectUri(), this.getRealState(config.getState()));
}
@Override
public String getRefreshUrl(AuthRefreshTokenEntity refreshTokenEntity) {
AuthConfig config = refreshTokenEntity.getConfig();
return MessageFormat.format(MICROSOFT_REFRESH_TOKEN_PATTERN, AuthSource.MICROSOFT.refresh(), config.getClientId(), config.getClientSecret(), config.getRedirectUri(), refreshTokenEntity.getRefreshToken());
}
@Override
public String getRevokeUrl(AuthRevokeEntity revokeEntity) {
return null;
}
}
......@@ -13,13 +13,6 @@ import java.text.MessageFormat;
*/
public class UrlBuilder {
private static final String GITHUB_ACCESS_TOKEN_PATTERN = "{0}?client_id={1}&client_secret={2}&code={3}&redirect_uri={4}";
private static final String GITHUB_USER_INFO_PATTERN = "{0}?access_token={1}";
private static final String GITHUB_AUTHORIZE_PATTERN = "{0}?client_id={1}&redirect_uri={2}&state={3}";
private static final String GOOGLE_AUTHORIZE_PATTERN = "{0}?client_id={1}&response_type=code&scope=openid%20email%20profile&redirect_uri={2}&state={3}";
private static final String GOOGLE_ACCESS_TOKEN_PATTERN = "{0}?client_id={1}&client_secret={2}&code={3}&redirect_uri={4}&grant_type=authorization_code";
private static final String GOOGLE_USER_INFO_PATTERN = "{0}?id_token={1}";
private static final String GITEE_ACCESS_TOKEN_PATTERN = "{0}?client_id={1}&client_secret={2}&grant_type=authorization_code&code={3}&redirect_uri={4}";
......@@ -54,16 +47,6 @@ public class UrlBuilder {
private static final String DOUYIN_USER_INFO_PATTERN = "{0}?access_token={1}&open_id={2}";
private static final String DOUYIN_REFRESH_TOKEN_PATTERN = "{0}?client_key={1}&refresh_token={2}&grant_type=refresh_token";
private static final String LINKEDIN_AUTHORIZE_PATTERN = "{0}?client_id={1}&redirect_uri={2}&state={3}&response_type=code&scope=r_liteprofile%20r_emailaddress%20w_member_social";
private static final String LINKEDIN_ACCESS_TOKEN_PATTERN = "{0}?client_id={1}&client_secret={2}&code={3}&redirect_uri={4}&grant_type=authorization_code";
private static final String LINKEDIN_USER_INFO_PATTERN = "{0}?projection=(id,firstName,lastName,profilePicture(displayImage~:playableStreams))";
private static final String LINKEDIN_REFRESH_TOKEN_PATTERN = "{0}?client_id={1}&client_secret={2}&refresh_token={3}&grant_type=refresh_token";
private static final String MICROSOFT_AUTHORIZE_PATTERN = "{0}?client_id={1}&response_type=code&redirect_uri={2}&response_mode=query&scope=offline_access%20user.read%20mail.read&state={3}";
private static final String MICROSOFT_ACCESS_TOKEN_PATTERN = "{0}?client_id={1}&client_secret={2}&scope=user.read%20mail.read&redirect_uri={3}&code={4}&grant_type=authorization_code";
private static final String MICROSOFT_USER_INFO_PATTERN = "{0}";
private static final String MICROSOFT_REFRESH_TOKEN_PATTERN = "{0}?client_id={1}&client_secret={2}&scope=user.read%20mail.read&redirect_uri={3}&refresh_token={4}&grant_type=refresh_token";
/**
......@@ -75,41 +58,6 @@ public class UrlBuilder {
return StringUtils.isEmpty(state) ? String.valueOf(System.currentTimeMillis()) : state;
}
/**
* 获取githubtoken的接口地址
*
* @param clientId github 应用的Client ID
* @param clientSecret github 应用的Client Secret
* @param code github 授权前的code,用来换token
* @param redirectUri 待跳转的页面
* @return full url
*/
public static String getGithubAccessTokenUrl(String clientId, String clientSecret, String code, String redirectUri) {
return MessageFormat.format(GITHUB_ACCESS_TOKEN_PATTERN, AuthSource.GITHUB.accessToken(), clientId, clientSecret, code, redirectUri);
}
/**
* 获取github用户详情的接口地址
*
* @param token github 应用的token
* @return full url
*/
public static String getGithubUserInfoUrl(String token) {
return MessageFormat.format(GITHUB_USER_INFO_PATTERN, AuthSource.GITHUB.userInfo(), token);
}
/**
* 获取github授权地址
*
* @param clientId github 应用的Client ID
* @param redirectUrl github 应用授权成功后的回调地址
* @param state 随机字符串,用于保持会话状态,防止CSRF攻击
* @return full url
*/
public static String getGithubAuthorizeUrl(String clientId, String redirectUrl, String state) {
return MessageFormat.format(GITHUB_AUTHORIZE_PATTERN, AuthSource.GITHUB.authorize(), clientId, redirectUrl, getState(state));
}
/**
* 获取gitee token的接口地址
*
......@@ -295,41 +243,6 @@ public class UrlBuilder {
return MessageFormat.format(ALIPAY_AUTHORIZE_PATTERN, AuthSource.ALIPAY.authorize(), clientId, redirectUrl, getState(state));
}
/**
* 获取Google授权地址
*
* @param clientId google 应用的Client ID
* @param redirectUrl google 应用授权成功后的回调地址
* @param state 随机字符串,用于保持会话状态,防止CSRF攻击
* @return full url
*/
public static String getGoogleAuthorizeUrl(String clientId, String redirectUrl, String state) {
return MessageFormat.format(GOOGLE_AUTHORIZE_PATTERN, AuthSource.GOOGLE.authorize(), clientId, redirectUrl, getState(state));
}
/**
* 获取Google token的接口地址
*
* @param clientId google 应用的Client ID
* @param clientSecret google 应用的Client Secret
* @param code google 授权前的code,用来换token
* @param redirectUri 待跳转的页面
* @return full url
*/
public static String getGoogleAccessTokenUrl(String clientId, String clientSecret, String code, String redirectUri) {
return MessageFormat.format(GOOGLE_ACCESS_TOKEN_PATTERN, AuthSource.GOOGLE.accessToken(), clientId, clientSecret, code, redirectUri);
}
/**
* 获取Google用户详情的接口地址
*
* @param token google 应用的token
* @return full url
*/
public static String getGoogleUserInfoUrl(String token) {
return MessageFormat.format(GOOGLE_USER_INFO_PATTERN, AuthSource.GOOGLE.userInfo(), token);
}
/**
* 获取Facebook授权地址
*
......@@ -411,97 +324,4 @@ public class UrlBuilder {
return MessageFormat.format(DOUYIN_REFRESH_TOKEN_PATTERN, AuthSource.DOUYIN.refresh(), clientId, refreshToken);
}
/**
* 获取Linkedin授权地址
*
* @param clientId Linkedin 应用的Client ID
* @param redirectUrl Linkedin 应用授权成功后的回调地址
* @param state 随机字符串,用于保持会话状态,防止CSRF攻击
* @return full url
*/
public static String getLinkedinAuthorizeUrl(String clientId, String redirectUrl, String state) {
return MessageFormat.format(LINKEDIN_AUTHORIZE_PATTERN, AuthSource.LINKEDIN.authorize(), clientId, redirectUrl, state);
}
/**
* 获取Linkedin token的接口地址
*
* @param clientId Linkedin 应用的Client ID
* @param clientSecret Linkedin 应用的Client Secret
* @param code Linkedin 授权前的code,用来换token
* @param redirectUrl Linkedin 应用授权成功后的回调地址
* @return full url
*/
public static String getLinkedinAccessTokenUrl(String clientId, String clientSecret, String code, String redirectUrl) {
return MessageFormat.format(LINKEDIN_ACCESS_TOKEN_PATTERN, AuthSource.LINKEDIN.accessToken(), clientId, clientSecret, code, redirectUrl);
}
/**
* 获取Linkedin用户详情的接口地址
*
* @return full url
*/
public static String getLinkedinUserInfoUrl() {
return MessageFormat.format(LINKEDIN_USER_INFO_PATTERN, AuthSource.LINKEDIN.userInfo());
}
/**
* 获取Linkedin 刷新令牌 地址
*
* @param clientId Linkedin 应用的client_key
* @param clientSecret Linkedin 应用的Client Secret
* @param refreshToken Linkedin 应用返回的refresh_token
* @return full url
*/
public static String getLinkedinRefreshUrl(String clientId, String clientSecret, String refreshToken) {
return MessageFormat.format(LINKEDIN_REFRESH_TOKEN_PATTERN, AuthSource.LINKEDIN.refresh(), clientId, clientSecret, refreshToken);
}
/**
* 获取微软授权地址
*
* @param clientId 微软 应用的Client ID
* @param redirectUrl 微软 应用授权成功后的回调地址
* @param state 随机字符串,用于保持会话状态,防止CSRF攻击
* @return full url
*/
public static String getMicrosoftAuthorizeUrl(String clientId, String redirectUrl, String state) {
return MessageFormat.format(MICROSOFT_AUTHORIZE_PATTERN, AuthSource.MICROSOFT.authorize(), clientId, redirectUrl, getState(state));
}
/**
* 获取微软 token的接口地址
*
* @param clientId 微软 应用的Client ID
* @param clientSecret 微软 应用的Client Secret
* @param redirectUrl 微软 应用授权成功后的回调地址
* @param code 微软 授权前的code,用来换token
* @return full url
*/
public static String getMicrosoftAccessTokenUrl(String clientId, String clientSecret, String redirectUrl, String code) {
return MessageFormat.format(MICROSOFT_ACCESS_TOKEN_PATTERN, AuthSource.MICROSOFT.accessToken(), clientId, clientSecret, redirectUrl, code);
}
/**
* 获取微软用户详情的接口地址
*
* @return full url
*/
public static String getMicrosoftUserInfoUrl() {
return MessageFormat.format(MICROSOFT_USER_INFO_PATTERN, AuthSource.MICROSOFT.userInfo());
}
/**
* 获取微软 刷新令牌 地址
*
* @param clientId 微软 应用的client_key
* @param clientSecret 微软 应用的Client Secret
* @param redirectUrl 微软 应用授权成功后的回调地址
* @param refreshToken 微软 应用返回的refresh_token
* @return full url
*/
public static String getMicrosoftRefreshUrl(String clientId, String clientSecret, String redirectUrl, String refreshToken) {
return MessageFormat.format(MICROSOFT_REFRESH_TOKEN_PATTERN, AuthSource.MICROSOFT.refresh(), clientId, clientSecret, redirectUrl, refreshToken);
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册