Merge pull request #2224 from lyen1688/feat-email-oauth-github-google
feat: 增加 GitHub 和 Google 邮箱快捷登录
This commit is contained in:
@@ -685,6 +685,16 @@ func TestAPIContracts(t *testing.T) {
|
||||
"oidc_connect_userinfo_email_path": "",
|
||||
"oidc_connect_userinfo_id_path": "",
|
||||
"oidc_connect_userinfo_username_path": "",
|
||||
"github_oauth_enabled": false,
|
||||
"github_oauth_client_id": "",
|
||||
"github_oauth_client_secret_configured": false,
|
||||
"github_oauth_redirect_url": "",
|
||||
"github_oauth_frontend_redirect_url": "/auth/oauth/callback",
|
||||
"google_oauth_enabled": false,
|
||||
"google_oauth_client_id": "",
|
||||
"google_oauth_client_secret_configured": false,
|
||||
"google_oauth_redirect_url": "",
|
||||
"google_oauth_frontend_redirect_url": "/auth/oauth/callback",
|
||||
"ops_monitoring_enabled": false,
|
||||
"ops_realtime_monitoring_enabled": true,
|
||||
"ops_query_mode_default": "auto",
|
||||
@@ -700,6 +710,16 @@ func TestAPIContracts(t *testing.T) {
|
||||
"auth_source_default_email_subscriptions": [],
|
||||
"auth_source_default_email_grant_on_signup": false,
|
||||
"auth_source_default_email_grant_on_first_bind": false,
|
||||
"auth_source_default_github_balance": 0,
|
||||
"auth_source_default_github_concurrency": 5,
|
||||
"auth_source_default_github_subscriptions": [],
|
||||
"auth_source_default_github_grant_on_signup": false,
|
||||
"auth_source_default_github_grant_on_first_bind": false,
|
||||
"auth_source_default_google_balance": 0,
|
||||
"auth_source_default_google_concurrency": 5,
|
||||
"auth_source_default_google_subscriptions": [],
|
||||
"auth_source_default_google_grant_on_signup": false,
|
||||
"auth_source_default_google_grant_on_first_bind": false,
|
||||
"auth_source_default_linuxdo_balance": 0,
|
||||
"auth_source_default_linuxdo_concurrency": 5,
|
||||
"auth_source_default_linuxdo_subscriptions": [],
|
||||
@@ -899,6 +919,16 @@ func TestAPIContracts(t *testing.T) {
|
||||
"oidc_connect_userinfo_email_path": "",
|
||||
"oidc_connect_userinfo_id_path": "",
|
||||
"oidc_connect_userinfo_username_path": "",
|
||||
"github_oauth_enabled": false,
|
||||
"github_oauth_client_id": "",
|
||||
"github_oauth_client_secret_configured": false,
|
||||
"github_oauth_redirect_url": "",
|
||||
"github_oauth_frontend_redirect_url": "/auth/oauth/callback",
|
||||
"google_oauth_enabled": false,
|
||||
"google_oauth_client_id": "",
|
||||
"google_oauth_client_secret_configured": false,
|
||||
"google_oauth_redirect_url": "",
|
||||
"google_oauth_frontend_redirect_url": "/auth/oauth/callback",
|
||||
"site_name": "Sub2API",
|
||||
"site_logo": "",
|
||||
"site_subtitle": "Subscription to API Conversion Platform",
|
||||
@@ -1007,6 +1037,16 @@ func TestAPIContracts(t *testing.T) {
|
||||
"auth_source_default_email_subscriptions": [],
|
||||
"auth_source_default_email_grant_on_signup": false,
|
||||
"auth_source_default_email_grant_on_first_bind": false,
|
||||
"auth_source_default_github_balance": 0,
|
||||
"auth_source_default_github_concurrency": 5,
|
||||
"auth_source_default_github_subscriptions": [],
|
||||
"auth_source_default_github_grant_on_signup": false,
|
||||
"auth_source_default_github_grant_on_first_bind": false,
|
||||
"auth_source_default_google_balance": 0,
|
||||
"auth_source_default_google_concurrency": 5,
|
||||
"auth_source_default_google_subscriptions": [],
|
||||
"auth_source_default_google_grant_on_signup": false,
|
||||
"auth_source_default_google_grant_on_first_bind": false,
|
||||
"auth_source_default_linuxdo_balance": 0,
|
||||
"auth_source_default_linuxdo_concurrency": 5,
|
||||
"auth_source_default_linuxdo_subscriptions": [],
|
||||
|
||||
@@ -40,6 +40,8 @@ func backendModeAllowsAuthPath(path string) bool {
|
||||
"/auth/oauth/wechat/callback",
|
||||
"/auth/oauth/wechat/payment/callback",
|
||||
"/auth/oauth/oidc/callback",
|
||||
"/auth/oauth/github/callback",
|
||||
"/auth/oauth/google/callback",
|
||||
"/auth/oauth/linuxdo/complete-registration",
|
||||
"/auth/oauth/wechat/complete-registration",
|
||||
"/auth/oauth/oidc/complete-registration",
|
||||
|
||||
@@ -246,6 +246,30 @@ func TestBackendModeAuthGuard(t *testing.T) {
|
||||
path: "/api/v1/auth/oauth/oidc/callback",
|
||||
wantStatus: http.StatusOK,
|
||||
},
|
||||
{
|
||||
name: "enabled_blocks_github_oauth_start",
|
||||
enabled: "true",
|
||||
path: "/api/v1/auth/oauth/github/start",
|
||||
wantStatus: http.StatusForbidden,
|
||||
},
|
||||
{
|
||||
name: "enabled_allows_github_oauth_callback",
|
||||
enabled: "true",
|
||||
path: "/api/v1/auth/oauth/github/callback",
|
||||
wantStatus: http.StatusOK,
|
||||
},
|
||||
{
|
||||
name: "enabled_blocks_google_oauth_start",
|
||||
enabled: "true",
|
||||
path: "/api/v1/auth/oauth/google/start",
|
||||
wantStatus: http.StatusForbidden,
|
||||
},
|
||||
{
|
||||
name: "enabled_allows_google_oauth_callback",
|
||||
enabled: "true",
|
||||
path: "/api/v1/auth/oauth/google/callback",
|
||||
wantStatus: http.StatusOK,
|
||||
},
|
||||
{
|
||||
name: "enabled_allows_oauth_pending_exchange",
|
||||
enabled: "true",
|
||||
|
||||
@@ -63,6 +63,22 @@ func RegisterAuthRoutes(
|
||||
FailureMode: middleware.RateLimitFailClose,
|
||||
}), h.Auth.ResetPassword)
|
||||
auth.GET("/oauth/linuxdo/start", h.Auth.LinuxDoOAuthStart)
|
||||
auth.GET("/oauth/github/start", h.Auth.GitHubOAuthStart)
|
||||
auth.GET("/oauth/github/callback", h.Auth.GitHubOAuthCallback)
|
||||
auth.POST("/oauth/github/complete-registration",
|
||||
rateLimiter.LimitWithOptions("oauth-github-complete", 10, time.Minute, middleware.RateLimitOptions{
|
||||
FailureMode: middleware.RateLimitFailClose,
|
||||
}),
|
||||
h.Auth.CompleteGitHubOAuthRegistration,
|
||||
)
|
||||
auth.GET("/oauth/google/start", h.Auth.GoogleOAuthStart)
|
||||
auth.GET("/oauth/google/callback", h.Auth.GoogleOAuthCallback)
|
||||
auth.POST("/oauth/google/complete-registration",
|
||||
rateLimiter.LimitWithOptions("oauth-google-complete", 10, time.Minute, middleware.RateLimitOptions{
|
||||
FailureMode: middleware.RateLimitFailClose,
|
||||
}),
|
||||
h.Auth.CompleteGoogleOAuthRegistration,
|
||||
)
|
||||
auth.GET("/oauth/linuxdo/bind/start", func(c *gin.Context) {
|
||||
query := c.Request.URL.Query()
|
||||
query.Set("intent", "bind_current_user")
|
||||
|
||||
Reference in New Issue
Block a user