From 666e6ad436f4df42e2c627d083d2c1af8921e45f Mon Sep 17 00:00:00 2001 From: Mike Bland Date: Tue, 31 Mar 2015 12:59:07 -0400 Subject: [PATCH] Add ProviderName field; use in sign_in template --- oauthproxy.go | 2 ++ providers/google.go | 1 + providers/google_test.go | 11 +++++++---- providers/provider_data.go | 9 +++++---- templates.go | 2 +- 5 files changed, 16 insertions(+), 9 deletions(-) diff --git a/oauthproxy.go b/oauthproxy.go index ca49f74..06d8621 100644 --- a/oauthproxy.go +++ b/oauthproxy.go @@ -279,11 +279,13 @@ func (p *OauthProxy) SignInPage(rw http.ResponseWriter, req *http.Request, code rw.WriteHeader(code) t := struct { + ProviderName string SignInMessage string CustomLogin bool Redirect string Version string }{ + ProviderName: p.provider.Data().ProviderName, SignInMessage: p.SignInMessage, CustomLogin: p.displayCustomLoginForm(), Redirect: req.URL.RequestURI(), diff --git a/providers/google.go b/providers/google.go index 9442113..c9955a9 100644 --- a/providers/google.go +++ b/providers/google.go @@ -13,6 +13,7 @@ type GoogleProvider struct { } func NewGoogleProvider(p *ProviderData) *GoogleProvider { + p.ProviderName = "Google" if p.LoginUrl.String() == "" { p.LoginUrl = &url.URL{Scheme: "https", Host: "accounts.google.com", diff --git a/providers/google_test.go b/providers/google_test.go index 68f2ff0..9ff4d00 100644 --- a/providers/google_test.go +++ b/providers/google_test.go @@ -11,15 +11,17 @@ import ( func newGoogleProvider() *GoogleProvider { return NewGoogleProvider( &ProviderData{ - LoginUrl: &url.URL{}, - RedeemUrl: &url.URL{}, - ProfileUrl: &url.URL{}, - Scope: ""}) + ProviderName: "", + LoginUrl: &url.URL{}, + RedeemUrl: &url.URL{}, + ProfileUrl: &url.URL{}, + Scope: ""}) } func TestGoogleProviderDefaults(t *testing.T) { p := newGoogleProvider() assert.NotEqual(t, nil, p) + assert.Equal(t, "Google", p.Data().ProviderName) assert.Equal(t, "https://accounts.google.com/o/oauth2/auth", p.Data().LoginUrl.String()) assert.Equal(t, "https://accounts.google.com/o/oauth2/token", @@ -45,6 +47,7 @@ func TestGoogleProviderOverrides(t *testing.T) { Path: "/oauth/profile"}, Scope: "profile"}) assert.NotEqual(t, nil, p) + assert.Equal(t, "Google", p.Data().ProviderName) assert.Equal(t, "https://example.com/oauth/auth", p.Data().LoginUrl.String()) assert.Equal(t, "https://example.com/oauth/token", diff --git a/providers/provider_data.go b/providers/provider_data.go index a533b6e..7b665cf 100644 --- a/providers/provider_data.go +++ b/providers/provider_data.go @@ -5,10 +5,11 @@ import ( ) type ProviderData struct { - LoginUrl *url.URL - RedeemUrl *url.URL - ProfileUrl *url.URL - Scope string + ProviderName string + LoginUrl *url.URL + RedeemUrl *url.URL + ProfileUrl *url.URL + Scope string } func (p *ProviderData) Data() *ProviderData { return p } diff --git a/templates.go b/templates.go index 02e8b82..b10158b 100644 --- a/templates.go +++ b/templates.go @@ -115,7 +115,7 @@ func getTemplates() *template.Template { {{ if .SignInMessage }}

{{.SignInMessage}}

{{ end}} -
+