Fix, improve + test google provider initiation
This commit is contained in:
@ -7,6 +7,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
@ -66,6 +67,26 @@ func NewGlobalConfig() Config {
|
|||||||
func NewConfig(args []string) (Config, error) {
|
func NewConfig(args []string) (Config, error) {
|
||||||
c := Config{
|
c := Config{
|
||||||
Rules: map[string]*Rule{},
|
Rules: map[string]*Rule{},
|
||||||
|
Providers: provider.Providers{
|
||||||
|
Google: provider.Google{
|
||||||
|
Scope: "https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email",
|
||||||
|
LoginURL: &url.URL{
|
||||||
|
Scheme: "https",
|
||||||
|
Host: "accounts.google.com",
|
||||||
|
Path: "/o/oauth2/auth",
|
||||||
|
},
|
||||||
|
TokenURL: &url.URL{
|
||||||
|
Scheme: "https",
|
||||||
|
Host: "www.googleapis.com",
|
||||||
|
Path: "/oauth2/v3/token",
|
||||||
|
},
|
||||||
|
UserURL: &url.URL{
|
||||||
|
Scheme: "https",
|
||||||
|
Host: "www.googleapis.com",
|
||||||
|
Path: "/oauth2/v2/userinfo",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
err := c.parseFlags(args)
|
err := c.parseFlags(args)
|
||||||
@ -100,9 +121,6 @@ func NewConfig(args []string) (Config, error) {
|
|||||||
c.Domains = append(c.Domains, c.DomainsLegacy...)
|
c.Domains = append(c.Domains, c.DomainsLegacy...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Provider defaults
|
|
||||||
c.Providers.Google.Build()
|
|
||||||
|
|
||||||
// Transformations
|
// Transformations
|
||||||
if len(c.Path) > 0 && c.Path[0] != '/' {
|
if len(c.Path) > 0 && c.Path[0] != '/' {
|
||||||
c.Path = "/" + c.Path
|
c.Path = "/" + c.Path
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package tfa
|
package tfa
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
@ -32,7 +33,29 @@ func TestConfigDefaults(t *testing.T) {
|
|||||||
assert.Equal("/_oauth", c.Path)
|
assert.Equal("/_oauth", c.Path)
|
||||||
assert.Len(c.Whitelist, 0)
|
assert.Len(c.Whitelist, 0)
|
||||||
|
|
||||||
|
assert.Equal("https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email", c.Providers.Google.Scope)
|
||||||
assert.Equal("", c.Providers.Google.Prompt)
|
assert.Equal("", c.Providers.Google.Prompt)
|
||||||
|
|
||||||
|
loginURL := &url.URL{
|
||||||
|
Scheme: "https",
|
||||||
|
Host: "accounts.google.com",
|
||||||
|
Path: "/o/oauth2/auth",
|
||||||
|
}
|
||||||
|
assert.Equal(loginURL, c.Providers.Google.LoginURL)
|
||||||
|
|
||||||
|
tokenURL := &url.URL{
|
||||||
|
Scheme: "https",
|
||||||
|
Host: "www.googleapis.com",
|
||||||
|
Path: "/oauth2/v3/token",
|
||||||
|
}
|
||||||
|
assert.Equal(tokenURL, c.Providers.Google.TokenURL)
|
||||||
|
|
||||||
|
userURL := &url.URL{
|
||||||
|
Scheme: "https",
|
||||||
|
Host: "www.googleapis.com",
|
||||||
|
Path: "/oauth2/v2/userinfo",
|
||||||
|
}
|
||||||
|
assert.Equal(userURL, c.Providers.Google.UserURL)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestConfigParseArgs(t *testing.T) {
|
func TestConfigParseArgs(t *testing.T) {
|
||||||
|
@ -18,24 +18,6 @@ type Google struct {
|
|||||||
UserURL *url.URL
|
UserURL *url.URL
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *Google) Build() {
|
|
||||||
g.LoginURL = &url.URL{
|
|
||||||
Scheme: "https",
|
|
||||||
Host: "accounts.google.com",
|
|
||||||
Path: "/o/oauth2/auth",
|
|
||||||
}
|
|
||||||
g.TokenURL = &url.URL{
|
|
||||||
Scheme: "https",
|
|
||||||
Host: "www.googleapis.com",
|
|
||||||
Path: "/oauth2/v3/token",
|
|
||||||
}
|
|
||||||
g.UserURL = &url.URL{
|
|
||||||
Scheme: "https",
|
|
||||||
Host: "www.googleapis.com",
|
|
||||||
Path: "/oauth2/v2/userinfo",
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (g *Google) GetLoginURL(redirectUri, state string) string {
|
func (g *Google) GetLoginURL(redirectUri, state string) string {
|
||||||
q := url.Values{}
|
q := url.Values{}
|
||||||
q.Set("client_id", g.ClientId)
|
q.Set("client_id", g.ClientId)
|
||||||
|
Reference in New Issue
Block a user