diff options
Diffstat (limited to 'server/auth/google')
-rw-r--r-- | server/auth/google/google.go | 4 | ||||
-rw-r--r-- | server/auth/google/google_test.go | 9 |
2 files changed, 7 insertions, 6 deletions
diff --git a/server/auth/google/google.go b/server/auth/google/google.go index 8c6f53b..305b6f4 100644 --- a/server/auth/google/google.go +++ b/server/auth/google/google.go @@ -43,7 +43,6 @@ func New(c *config.Auth) (*Config, error) { config: &oauth2.Config{ ClientID: c.OauthClientID, ClientSecret: c.OauthClientSecret, - RedirectURL: c.OauthCallbackURL, Endpoint: google.Endpoint, Scopes: []string{googleapi.UserinfoEmailScope, googleapi.UserinfoProfileScope}, }, @@ -101,7 +100,8 @@ func (c *Config) Revoke(token *oauth2.Token) error { } // StartSession retrieves an authentication endpoint from Google. -func (c *Config) StartSession(state string) *auth.Session { +func (c *Config) StartSession(state string, r *http.Request) *auth.Session { + c.config.RedirectURL = auth.Oauth2RedirectURL(r) return &auth.Session{ AuthURL: c.config.AuthCodeURL(state, oauth2.SetAuthURLParam("hd", c.domain)), } diff --git a/server/auth/google/google_test.go b/server/auth/google/google_test.go index b3d2633..4d6191b 100644 --- a/server/auth/google/google_test.go +++ b/server/auth/google/google_test.go @@ -2,6 +2,7 @@ package google import ( "fmt" + "net/http" "testing" "github.com/nsheridan/cashier/server/config" @@ -22,7 +23,6 @@ func TestNew(t *testing.T) { a.NoError(err) a.Equal(p.config.ClientID, oauthClientID) a.Equal(p.config.ClientSecret, oauthClientSecret) - a.Equal(p.config.RedirectURL, oauthCallbackURL) a.Equal(p.domain, domain) a.Equal(p.whitelist, map[string]bool{"user": true}) } @@ -31,7 +31,6 @@ func TestWhitelist(t *testing.T) { c := &config.Auth{ OauthClientID: oauthClientID, OauthClientSecret: oauthClientSecret, - OauthCallbackURL: oauthCallbackURL, ProviderOpts: map[string]string{"domain": ""}, UsersWhitelist: []string{}, } @@ -56,7 +55,10 @@ func TestStartSession(t *testing.T) { p, err := newGoogle() a.NoError(err) - s := p.StartSession("test_state") + r := &http.Request{ + Host: oauthCallbackURL, + } + s := p.StartSession("test_state", r) a.Contains(s.AuthURL, "accounts.google.com/o/oauth2/auth") a.Contains(s.AuthURL, "state=test_state") a.Contains(s.AuthURL, fmt.Sprintf("hd=%s", domain)) @@ -67,7 +69,6 @@ func newGoogle() (*Config, error) { c := &config.Auth{ OauthClientID: oauthClientID, OauthClientSecret: oauthClientSecret, - OauthCallbackURL: oauthCallbackURL, ProviderOpts: map[string]string{"domain": domain}, UsersWhitelist: users, } |