优化

pull/31/head
smallbun 2023-08-19 13:49:19 +08:00
parent 35d9df8b0d
commit a61f6fe100
5 changed files with 17 additions and 18 deletions

View File

@ -35,12 +35,11 @@ public enum IdentityProviderCategory implements BaseEnum {
/** /**
* *
*/ */
social("social", "社交", social("social", "社交", Lists.newArrayList(
Lists.newArrayList( IdentityProviderType.QQ,
IdentityProviderType.QQ, IdentityProviderType.WECHAT_QR,
IdentityProviderType.WECHAT_QR, IdentityProviderType.GITEE_OAUTH,
IdentityProviderType.GITHUB, IdentityProviderType.GITHUB_OAUTH)),
IdentityProviderType.GITHUB)),
/** /**
* *
*/ */

View File

@ -103,7 +103,7 @@ public final class IdentityProviderType {
/** /**
* GITHUB * GITHUB
*/ */
public static final IdentityProviderType GITHUB = new IdentityProviderType( public static final IdentityProviderType GITHUB_OAUTH = new IdentityProviderType(
"github_oauth", "GITHUB认证", "通过GITHUB进行身份认证"); "github_oauth", "GITHUB认证", "通过GITHUB进行身份认证");
private final String value; private final String value;

View File

@ -49,7 +49,7 @@ import jakarta.servlet.FilterChain;
import jakarta.servlet.ServletException; import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse; import jakarta.servlet.http.HttpServletResponse;
import static cn.topiam.employee.authentication.common.IdentityProviderType.GITHUB; import static cn.topiam.employee.authentication.common.IdentityProviderType.GITHUB_OAUTH;
import static cn.topiam.employee.authentication.common.constant.AuthenticationConstants.PROVIDER_CODE; import static cn.topiam.employee.authentication.common.constant.AuthenticationConstants.PROVIDER_CODE;
import static cn.topiam.employee.authentication.github.constant.GithubAuthenticationConstants.URL_AUTHORIZE; import static cn.topiam.employee.authentication.github.constant.GithubAuthenticationConstants.URL_AUTHORIZE;
import static cn.topiam.employee.authentication.github.filter.GithubOAuth2LoginAuthenticationFilter.getLoginUrl; import static cn.topiam.employee.authentication.github.filter.GithubOAuth2LoginAuthenticationFilter.getLoginUrl;
@ -70,7 +70,7 @@ public class GithubOAuth2AuthorizationRequestRedirectFilter extends OncePerReque
* AntPathRequestMatcher * AntPathRequestMatcher
*/ */
public static final AntPathRequestMatcher GITHUB_REQUEST_MATCHER = new AntPathRequestMatcher( public static final AntPathRequestMatcher GITHUB_REQUEST_MATCHER = new AntPathRequestMatcher(
GITHUB.getAuthorizationPathPrefix() + "/" + "{" + PROVIDER_CODE + "}", GITHUB_OAUTH.getAuthorizationPathPrefix() + "/" + "{" + PROVIDER_CODE + "}",
HttpMethod.GET.name()); HttpMethod.GET.name());
/** /**

View File

@ -52,7 +52,7 @@ import cn.topiam.employee.support.util.HttpUrlUtils;
import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse; import jakarta.servlet.http.HttpServletResponse;
import static cn.topiam.employee.authentication.common.IdentityProviderType.GITHUB; import static cn.topiam.employee.authentication.common.IdentityProviderType.GITHUB_OAUTH;
import static cn.topiam.employee.authentication.common.constant.AuthenticationConstants.*; import static cn.topiam.employee.authentication.common.constant.AuthenticationConstants.*;
import static cn.topiam.employee.authentication.github.constant.GithubAuthenticationConstants.*; import static cn.topiam.employee.authentication.github.constant.GithubAuthenticationConstants.*;
@ -66,7 +66,7 @@ import static cn.topiam.employee.authentication.github.constant.GithubAuthentica
public class GithubOAuth2LoginAuthenticationFilter extends public class GithubOAuth2LoginAuthenticationFilter extends
AbstractIdpAuthenticationProcessingFilter { AbstractIdpAuthenticationProcessingFilter {
final String ERROR_CODE = "error"; final String ERROR_CODE = "error";
public final static String DEFAULT_FILTER_PROCESSES_URI = GITHUB public final static String DEFAULT_FILTER_PROCESSES_URI = GITHUB_OAUTH
.getLoginPathPrefix() + "/" + "{" + PROVIDER_CODE + "}"; .getLoginPathPrefix() + "/" + "{" + PROVIDER_CODE + "}";
public static final AntPathRequestMatcher REQUEST_MATCHER = new AntPathRequestMatcher( public static final AntPathRequestMatcher REQUEST_MATCHER = new AntPathRequestMatcher(
DEFAULT_FILTER_PROCESSES_URI, HttpMethod.GET.name()); DEFAULT_FILTER_PROCESSES_URI, HttpMethod.GET.name());
@ -150,8 +150,8 @@ public class GithubOAuth2LoginAuthenticationFilter extends
} }
// 返回 // 返回
String id = result.getString("id"); String id = result.getString("id");
IdpUserDetails idpUserDetails = IdpUserDetails.builder().openId(id).providerType(GITHUB) IdpUserDetails idpUserDetails = IdpUserDetails.builder().openId(id)
.providerCode(providerCode).providerId(providerId).build(); .providerType(GITHUB_OAUTH).providerCode(providerCode).providerId(providerId).build();
return attemptAuthentication(request, response, idpUserDetails); return attemptAuthentication(request, response, idpUserDetails);
} }
@ -172,8 +172,8 @@ public class GithubOAuth2LoginAuthenticationFilter extends
} }
public static String getLoginUrl(String providerId) { public static String getLoginUrl(String providerId) {
String url = ServerHelp.getPortalPublicBaseUrl() + "/" + GITHUB.getLoginPathPrefix() + "/" String url = ServerHelp.getPortalPublicBaseUrl() + "/" + GITHUB_OAUTH.getLoginPathPrefix()
+ providerId; + "/" + providerId;
return HttpUrlUtils.format(url); return HttpUrlUtils.format(url);
} }

View File

@ -262,7 +262,7 @@ public interface IdentityProviderConverter {
} else if (type.equals(FEISHU_OAUTH.value())) { } else if (type.equals(FEISHU_OAUTH.value())) {
identityProviderConfig = config.to(FeiShuIdpScanCodeConfig.class); identityProviderConfig = config.to(FeiShuIdpScanCodeConfig.class);
//GITHUB认证 //GITHUB认证
} else if (type.equals(GITHUB.value())) { } else if (type.equals(GITHUB_OAUTH.value())) {
identityProviderConfig = config.to(GithubIdpOauthConfig.class); identityProviderConfig = config.to(GithubIdpOauthConfig.class);
} }
//Gitee //Gitee
@ -319,8 +319,8 @@ public interface IdentityProviderConverter {
if (WECHAT_WEB_PAGE.value().equals(type)) { if (WECHAT_WEB_PAGE.value().equals(type)) {
return WECHAT_WEB_PAGE; return WECHAT_WEB_PAGE;
} }
if (GITHUB.value().equals(type)) { if (GITHUB_OAUTH.value().equals(type)) {
return GITHUB; return GITHUB_OAUTH;
} }
if (GITEE_OAUTH.value().equals(type)) { if (GITEE_OAUTH.value().equals(type)) {
return GITEE_OAUTH; return GITEE_OAUTH;