Merge pull request #78 from 18F/generalize-templates

Add ProviderName field; use in sign_in template
This commit is contained in:
Jehiah Czebotar 2015-03-31 13:21:03 -04:00
commit 243dbb77fb
5 changed files with 16 additions and 9 deletions

View File

@ -279,11 +279,13 @@ func (p *OauthProxy) SignInPage(rw http.ResponseWriter, req *http.Request, code
rw.WriteHeader(code) rw.WriteHeader(code)
t := struct { t := struct {
ProviderName string
SignInMessage string SignInMessage string
CustomLogin bool CustomLogin bool
Redirect string Redirect string
Version string Version string
}{ }{
ProviderName: p.provider.Data().ProviderName,
SignInMessage: p.SignInMessage, SignInMessage: p.SignInMessage,
CustomLogin: p.displayCustomLoginForm(), CustomLogin: p.displayCustomLoginForm(),
Redirect: req.URL.RequestURI(), Redirect: req.URL.RequestURI(),

View File

@ -13,6 +13,7 @@ type GoogleProvider struct {
} }
func NewGoogleProvider(p *ProviderData) *GoogleProvider { func NewGoogleProvider(p *ProviderData) *GoogleProvider {
p.ProviderName = "Google"
if p.LoginUrl.String() == "" { if p.LoginUrl.String() == "" {
p.LoginUrl = &url.URL{Scheme: "https", p.LoginUrl = &url.URL{Scheme: "https",
Host: "accounts.google.com", Host: "accounts.google.com",

View File

@ -11,15 +11,17 @@ import (
func newGoogleProvider() *GoogleProvider { func newGoogleProvider() *GoogleProvider {
return NewGoogleProvider( return NewGoogleProvider(
&ProviderData{ &ProviderData{
LoginUrl: &url.URL{}, ProviderName: "",
RedeemUrl: &url.URL{}, LoginUrl: &url.URL{},
ProfileUrl: &url.URL{}, RedeemUrl: &url.URL{},
Scope: ""}) ProfileUrl: &url.URL{},
Scope: ""})
} }
func TestGoogleProviderDefaults(t *testing.T) { func TestGoogleProviderDefaults(t *testing.T) {
p := newGoogleProvider() p := newGoogleProvider()
assert.NotEqual(t, nil, p) assert.NotEqual(t, nil, p)
assert.Equal(t, "Google", p.Data().ProviderName)
assert.Equal(t, "https://accounts.google.com/o/oauth2/auth", assert.Equal(t, "https://accounts.google.com/o/oauth2/auth",
p.Data().LoginUrl.String()) p.Data().LoginUrl.String())
assert.Equal(t, "https://accounts.google.com/o/oauth2/token", assert.Equal(t, "https://accounts.google.com/o/oauth2/token",
@ -45,6 +47,7 @@ func TestGoogleProviderOverrides(t *testing.T) {
Path: "/oauth/profile"}, Path: "/oauth/profile"},
Scope: "profile"}) Scope: "profile"})
assert.NotEqual(t, nil, p) assert.NotEqual(t, nil, p)
assert.Equal(t, "Google", p.Data().ProviderName)
assert.Equal(t, "https://example.com/oauth/auth", assert.Equal(t, "https://example.com/oauth/auth",
p.Data().LoginUrl.String()) p.Data().LoginUrl.String())
assert.Equal(t, "https://example.com/oauth/token", assert.Equal(t, "https://example.com/oauth/token",

View File

@ -5,10 +5,11 @@ import (
) )
type ProviderData struct { type ProviderData struct {
LoginUrl *url.URL ProviderName string
RedeemUrl *url.URL LoginUrl *url.URL
ProfileUrl *url.URL RedeemUrl *url.URL
Scope string ProfileUrl *url.URL
Scope string
} }
func (p *ProviderData) Data() *ProviderData { return p } func (p *ProviderData) Data() *ProviderData { return p }

View File

@ -115,7 +115,7 @@ func getTemplates() *template.Template {
{{ if .SignInMessage }} {{ if .SignInMessage }}
<p>{{.SignInMessage}}</p> <p>{{.SignInMessage}}</p>
{{ end}} {{ end}}
<button type="submit" class="btn">Sign in with a Google Account</button><br/> <button type="submit" class="btn">Sign in with a {{.ProviderName}} Account</button><br/>
</form> </form>
</div> </div>