Skip to content

Commit fa61c84

Browse files
committed
Fix, improve + test google provider initiation
1 parent 3cc9cd1 commit fa61c84

File tree

3 files changed

+44
-21
lines changed

3 files changed

+44
-21
lines changed

internal/config.go

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"fmt"
88
"io"
99
"io/ioutil"
10+
"net/url"
1011
"os"
1112
"regexp"
1213
"strconv"
@@ -66,6 +67,26 @@ func NewGlobalConfig() Config {
6667
func NewConfig(args []string) (Config, error) {
6768
c := Config{
6869
Rules: map[string]*Rule{},
70+
Providers: provider.Providers{
71+
Google: provider.Google{
72+
Scope: "https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email",
73+
LoginURL: &url.URL{
74+
Scheme: "https",
75+
Host: "accounts.google.com",
76+
Path: "/o/oauth2/auth",
77+
},
78+
TokenURL: &url.URL{
79+
Scheme: "https",
80+
Host: "www.googleapis.com",
81+
Path: "/oauth2/v3/token",
82+
},
83+
UserURL: &url.URL{
84+
Scheme: "https",
85+
Host: "www.googleapis.com",
86+
Path: "/oauth2/v2/userinfo",
87+
},
88+
},
89+
},
6990
}
7091

7192
err := c.parseFlags(args)
@@ -100,9 +121,6 @@ func NewConfig(args []string) (Config, error) {
100121
c.Domains = append(c.Domains, c.DomainsLegacy...)
101122
}
102123

103-
// Provider defaults
104-
c.Providers.Google.Build()
105-
106124
// Transformations
107125
if len(c.Path) > 0 && c.Path[0] != '/' {
108126
c.Path = "/" + c.Path

internal/config_test.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package tfa
22

33
import (
4+
"net/url"
45
"os"
56
"testing"
67
"time"
@@ -32,7 +33,29 @@ func TestConfigDefaults(t *testing.T) {
3233
assert.Equal("/_oauth", c.Path)
3334
assert.Len(c.Whitelist, 0)
3435

36+
assert.Equal("https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email", c.Providers.Google.Scope)
3537
assert.Equal("", c.Providers.Google.Prompt)
38+
39+
loginURL := &url.URL{
40+
Scheme: "https",
41+
Host: "accounts.google.com",
42+
Path: "/o/oauth2/auth",
43+
}
44+
assert.Equal(loginURL, c.Providers.Google.LoginURL)
45+
46+
tokenURL := &url.URL{
47+
Scheme: "https",
48+
Host: "www.googleapis.com",
49+
Path: "/oauth2/v3/token",
50+
}
51+
assert.Equal(tokenURL, c.Providers.Google.TokenURL)
52+
53+
userURL := &url.URL{
54+
Scheme: "https",
55+
Host: "www.googleapis.com",
56+
Path: "/oauth2/v2/userinfo",
57+
}
58+
assert.Equal(userURL, c.Providers.Google.UserURL)
3659
}
3760

3861
func TestConfigParseArgs(t *testing.T) {

internal/provider/google.go

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,6 @@ type Google struct {
1818
UserURL *url.URL
1919
}
2020

21-
func (g *Google) Build() {
22-
g.LoginURL = &url.URL{
23-
Scheme: "https",
24-
Host: "accounts.google.com",
25-
Path: "/o/oauth2/auth",
26-
}
27-
g.TokenURL = &url.URL{
28-
Scheme: "https",
29-
Host: "www.googleapis.com",
30-
Path: "/oauth2/v3/token",
31-
}
32-
g.UserURL = &url.URL{
33-
Scheme: "https",
34-
Host: "www.googleapis.com",
35-
Path: "/oauth2/v2/userinfo",
36-
}
37-
}
38-
3921
func (g *Google) GetLoginURL(redirectUri, state string) string {
4022
q := url.Values{}
4123
q.Set("client_id", g.ClientId)

0 commit comments

Comments
 (0)