]> git.feebdaed.xyz Git - lgtm-rsvp.git/commitdiff
fix oauth url
authorseantywork <seantywork@gmail.com>
Sat, 18 Jan 2025 10:55:04 +0000 (10:55 +0000)
committerseantywork <seantywork@gmail.com>
Sat, 18 Jan 2025 10:55:04 +0000 (10:55 +0000)
pkg/auth/auth_oauth2.go
pkg/server/server.go

index c075cb4164ebc2a07d1d6a516debc107e80782c5..630593b09acb11c450899d8065c07ec2b2db00b9 100644 (file)
@@ -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
 
 }
 
index c88ad276dce0692aec2d8587421f21aed8d5b428..6c57ece6d2f7b6f6aaef43178b8f12376137a56a 100644 (file)
@@ -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)