From: seantywork Date: Sat, 18 Jan 2025 10:55:04 +0000 (+0000) Subject: fix oauth url X-Git-Url: https://git.feebdaed.xyz/?a=commitdiff_plain;h=7a16e9227837363292f98c023e27c62e8d53d39a;p=lgtm-rsvp.git fix oauth url --- diff --git a/pkg/auth/auth_oauth2.go b/pkg/auth/auth_oauth2.go index c075cb4..630593b 100644 --- a/pkg/auth/auth_oauth2.go +++ b/pkg/auth/auth_oauth2.go @@ -8,6 +8,7 @@ import ( "log" "net/http" "os" + "strings" pkgglob "our-wedding-rsvp/pkg/glob" @@ -78,7 +79,7 @@ func GetOAuthJSON() (OAuthJSON, error) { } -func GenerateGoogleOauthConfig() *oauth2.Config { +func GenerateGoogleOauthConfig() (*oauth2.Config, error) { google_oauth_config := &oauth2.Config{ ClientID: OAUTH_JSON.Web.ClientID, @@ -87,11 +88,30 @@ func GenerateGoogleOauthConfig() *oauth2.Config { Endpoint: google.Endpoint, } - google_oauth_config.RedirectURL = pkgglob.G_CONF.Url + found := 0 + + redirectlen := len(OAUTH_JSON.Web.RedirectUris) + + for i := 0; i < redirectlen; i++ { + + if strings.HasPrefix(OAUTH_JSON.Web.RedirectUris[i], pkgglob.G_CONF.Url) { + + google_oauth_config.RedirectURL = OAUTH_JSON.Web.RedirectUris[i] + + found = 1 + + break + } + + } + + if found == 0 { + return nil, fmt.Errorf("failed to find redirect url") + } log.Println(google_oauth_config.RedirectURL) - return google_oauth_config + return google_oauth_config, nil } diff --git a/pkg/server/server.go b/pkg/server/server.go index c88ad27..6c57ece 100644 --- a/pkg/server/server.go +++ b/pkg/server/server.go @@ -84,7 +84,7 @@ func configureServer(e *gin.Engine) error { e.GET("/api/oauth2/google/signin", pkgserverapi.OauthGoogleLogin) - e.GET("/oauth2/google/callback", pkgserverapi.OauthGoogleCallback) + e.GET("/api/oauth2/google/callback", pkgserverapi.OauthGoogleCallback) e.POST("/api/signin", pkgserverapi.Login)