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)
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(),

View File

@ -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",

View File

@ -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",

View File

@ -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 }

View File

@ -115,7 +115,7 @@ func getTemplates() *template.Template {
{{ if .SignInMessage }}
<p>{{.SignInMessage}}</p>
{{ 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>
</div>