File tree Expand file tree Collapse file tree 3 files changed +44
-21
lines changed Expand file tree Collapse file tree 3 files changed +44
-21
lines changed Original file line number Diff line number Diff line change 7
7
"fmt"
8
8
"io"
9
9
"io/ioutil"
10
+ "net/url"
10
11
"os"
11
12
"regexp"
12
13
"strconv"
@@ -66,6 +67,26 @@ func NewGlobalConfig() Config {
66
67
func NewConfig (args []string ) (Config , error ) {
67
68
c := Config {
68
69
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
+ },
69
90
}
70
91
71
92
err := c .parseFlags (args )
@@ -100,9 +121,6 @@ func NewConfig(args []string) (Config, error) {
100
121
c .Domains = append (c .Domains , c .DomainsLegacy ... )
101
122
}
102
123
103
- // Provider defaults
104
- c .Providers .Google .Build ()
105
-
106
124
// Transformations
107
125
if len (c .Path ) > 0 && c .Path [0 ] != '/' {
108
126
c .Path = "/" + c .Path
Original file line number Diff line number Diff line change 1
1
package tfa
2
2
3
3
import (
4
+ "net/url"
4
5
"os"
5
6
"testing"
6
7
"time"
@@ -32,7 +33,29 @@ func TestConfigDefaults(t *testing.T) {
32
33
assert .Equal ("/_oauth" , c .Path )
33
34
assert .Len (c .Whitelist , 0 )
34
35
36
+ assert .Equal ("https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email" , c .Providers .Google .Scope )
35
37
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 )
36
59
}
37
60
38
61
func TestConfigParseArgs (t * testing.T ) {
Original file line number Diff line number Diff line change @@ -18,24 +18,6 @@ type Google struct {
18
18
UserURL * url.URL
19
19
}
20
20
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
-
39
21
func (g * Google ) GetLoginURL (redirectUri , state string ) string {
40
22
q := url.Values {}
41
23
q .Set ("client_id" , g .ClientId )
You can’t perform that action at this time.
0 commit comments