| 112 | </html>`)) |
| 113 | |
| 114 | func NewUserAuth(cfg *config.OAuthConfig, store *identity.Store, production bool) *UserAuth { |
| 115 | // Derive the user auth callback URL from the existing redirect URL. |
| 116 | // e.g. "https://e2a.example.com/api/verify/callback" → "https://e2a.example.com/api/auth/callback" |
| 117 | callbackURL := cfg.RedirectURL |
| 118 | baseURL := "" |
| 119 | if u, err := url.Parse(cfg.RedirectURL); err == nil && u.Host != "" { |
| 120 | u.Path = "/api/auth/callback" |
| 121 | callbackURL = u.String() |
| 122 | baseURL = u.Scheme + "://" + u.Host |
| 123 | } |
| 124 | |
| 125 | return &UserAuth{ |
| 126 | oauthConfig: &oauth2.Config{ |
| 127 | ClientID: cfg.GoogleClientID, |
| 128 | ClientSecret: cfg.GoogleClientSecret, |
| 129 | RedirectURL: callbackURL, |
| 130 | Scopes: []string{"openid", "email", "profile"}, |
| 131 | Endpoint: google.Endpoint, |
| 132 | }, |
| 133 | store: store, |
| 134 | secure: production, |
| 135 | baseURL: baseURL, |
| 136 | userInfoURL: defaultUserInfoURL, |
| 137 | } |
| 138 | } |
| 139 | |
| 140 | // NewUserAuthWithOAuthConfig creates a UserAuth with a custom oauth2.Config and |
| 141 | // userinfo URL. This is intended for testing against fake OAuth servers. |