aboutsummaryrefslogtreecommitdiff
path: root/server/auth/google
diff options
context:
space:
mode:
Diffstat (limited to 'server/auth/google')
-rw-r--r--server/auth/google/google.go4
-rw-r--r--server/auth/google/google_test.go9
2 files changed, 6 insertions, 7 deletions
diff --git a/server/auth/google/google.go b/server/auth/google/google.go
index 305b6f4..8c6f53b 100644
--- a/server/auth/google/google.go
+++ b/server/auth/google/google.go
@@ -43,6 +43,7 @@ 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},
},
@@ -100,8 +101,7 @@ func (c *Config) Revoke(token *oauth2.Token) error {
}
// StartSession retrieves an authentication endpoint from Google.
-func (c *Config) StartSession(state string, r *http.Request) *auth.Session {
- c.config.RedirectURL = auth.Oauth2RedirectURL(r)
+func (c *Config) StartSession(state string) *auth.Session {
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 4d6191b..b3d2633 100644
--- a/server/auth/google/google_test.go
+++ b/server/auth/google/google_test.go
@@ -2,7 +2,6 @@ package google
import (
"fmt"
- "net/http"
"testing"
"github.com/nsheridan/cashier/server/config"
@@ -23,6 +22,7 @@ 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,6 +31,7 @@ func TestWhitelist(t *testing.T) {
c := &config.Auth{
OauthClientID: oauthClientID,
OauthClientSecret: oauthClientSecret,
+ OauthCallbackURL: oauthCallbackURL,
ProviderOpts: map[string]string{"domain": ""},
UsersWhitelist: []string{},
}
@@ -55,10 +56,7 @@ func TestStartSession(t *testing.T) {
p, err := newGoogle()
a.NoError(err)
- r := &http.Request{
- Host: oauthCallbackURL,
- }
- s := p.StartSession("test_state", r)
+ s := p.StartSession("test_state")
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))
@@ -69,6 +67,7 @@ func newGoogle() (*Config, error) {
c := &config.Auth{
OauthClientID: oauthClientID,
OauthClientSecret: oauthClientSecret,
+ OauthCallbackURL: oauthCallbackURL,
ProviderOpts: map[string]string{"domain": domain},
UsersWhitelist: users,
}