aboutsummaryrefslogtreecommitdiff
path: root/server/auth/github
diff options
context:
space:
mode:
Diffstat (limited to 'server/auth/github')
-rw-r--r--server/auth/github/github.go4
-rw-r--r--server/auth/github/github_test.go10
2 files changed, 7 insertions, 7 deletions
diff --git a/server/auth/github/github.go b/server/auth/github/github.go
index 46cf76a..c985eed 100644
--- a/server/auth/github/github.go
+++ b/server/auth/github/github.go
@@ -40,7 +40,6 @@ func New(c *config.Auth) (*Config, error) {
config: &oauth2.Config{
ClientID: c.OauthClientID,
ClientSecret: c.OauthClientSecret,
- RedirectURL: c.OauthCallbackURL,
Endpoint: github.Endpoint,
Scopes: []string{
string(githubapi.ScopeUser),
@@ -91,7 +90,8 @@ func (c *Config) Revoke(token *oauth2.Token) error {
}
// StartSession retrieves an authentication endpoint from Github.
-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),
}
diff --git a/server/auth/github/github_test.go b/server/auth/github/github_test.go
index 8c51f4f..d9d5f00 100644
--- a/server/auth/github/github_test.go
+++ b/server/auth/github/github_test.go
@@ -2,6 +2,7 @@ package github
import (
"fmt"
+ "net/http"
"testing"
"github.com/nsheridan/cashier/server/config"
@@ -22,13 +23,11 @@ func TestNew(t *testing.T) {
p, _ := New(&config.Auth{
OauthClientID: oauthClientID,
OauthClientSecret: oauthClientSecret,
- OauthCallbackURL: oauthCallbackURL,
ProviderOpts: map[string]string{"organization": organization},
UsersWhitelist: users,
})
a.Equal(p.config.ClientID, oauthClientID)
a.Equal(p.config.ClientSecret, oauthClientSecret)
- a.Equal(p.config.RedirectURL, oauthCallbackURL)
a.Equal(p.organization, organization)
a.Equal(p.whitelist, map[string]bool{"user": true})
}
@@ -37,7 +36,6 @@ func TestWhitelist(t *testing.T) {
c := &config.Auth{
OauthClientID: oauthClientID,
OauthClientSecret: oauthClientSecret,
- OauthCallbackURL: oauthCallbackURL,
ProviderOpts: map[string]string{"organization": ""},
UsersWhitelist: []string{},
}
@@ -61,7 +59,10 @@ func TestStartSession(t *testing.T) {
a := assert.New(t)
p, _ := newGithub()
- s := p.StartSession("test_state")
+ r := &http.Request{
+ Host: oauthCallbackURL,
+ }
+ s := p.StartSession("test_state", r)
a.Contains(s.AuthURL, "github.com/login/oauth/authorize")
a.Contains(s.AuthURL, "state=test_state")
a.Contains(s.AuthURL, fmt.Sprintf("client_id=%s", oauthClientID))
@@ -71,7 +72,6 @@ func newGithub() (*Config, error) {
c := &config.Auth{
OauthClientID: oauthClientID,
OauthClientSecret: oauthClientSecret,
- OauthCallbackURL: oauthCallbackURL,
ProviderOpts: map[string]string{"organization": organization},
}
return New(c)