git.iko.soy/typeable/oauth2-proxy
on master help sign in
Merge pull request #472 from jmcarp/drop-myusa

Drop deprecated MyUSA provider.

commitf6828631cfe769ec452e902af106193994783ff8 authorJehiah Czebotar <jehiah@gmail.com> dateSun 8 Oct 2017, 13:05 (9 years ago) parent7b26256d118cb7
5 files changed+5−206
README.md−5 providers/internal_util.go+5 providers/myusa.go−58 providers/myusa_test.go−141 providers/providers.go−2
README.md−5
@@ -32,7 +32,6 @@ Valid providers are :
3232* [GitHub](#github-auth-provider)
3333* [GitLab](#gitlab-auth-provider)
3434* [LinkedIn](#linkedin-auth-provider)
35−* [MyUSA](#myusa-auth-provider)
3635
3736The provider can be selected using the `provider` configuration value.
3837
@@ -129,10 +128,6 @@ For LinkedIn, the registration steps are:
1291283. Fill in the remaining required fields and Save.
1301294. Take note of the **Consumer Key / API Key** and **Consumer Secret / Secret Key**
131130
132−### MyUSA Auth Provider
133−
134−The [MyUSA](https://alpha.my.usa.gov) authentication service ([GitHub](https://github.com/18F/myusa))
135−
136131### Microsoft Azure AD Provider
137132
138133For adding an application to the Microsoft Azure AD follow [these steps to add an application](https://azure.microsoft.com/en-us/documentation/articles/active-directory-integrating-applications/).
providers/internal_util.go+5
@@ -72,3 +72,8 @@ func validateToken(p Provider, access_token string, header http.Header) bool {
7272 log.Printf("token validation request failed: status %d - %s", resp.StatusCode, body)
7373 return false
7474}
75+
76+func updateURL(url *url.URL, hostname string) {
77+ url.Scheme = "http"
78+ url.Host = hostname
79+}
providers/myusa.godeleted−58
@@ -1,58 +0,0 @@
1−package providers
2−
3−import (
4− "log"
5− "net/http"
6− "net/url"
7−
8− "github.com/bitly/oauth2_proxy/api"
9−)
10−
11−type MyUsaProvider struct {
12− *ProviderData
13−}
14−
15−func NewMyUsaProvider(p *ProviderData) *MyUsaProvider {
16− const myUsaHost string = "alpha.my.usa.gov"
17−
18− p.ProviderName = "MyUSA"
19− if p.LoginURL.String() == "" {
20− p.LoginURL = &url.URL{Scheme: "https",
21− Host: myUsaHost,
22− Path: "/oauth/authorize"}
23− }
24− if p.RedeemURL.String() == "" {
25− p.RedeemURL = &url.URL{Scheme: "https",
26− Host: myUsaHost,
27− Path: "/oauth/token"}
28− }
29− if p.ProfileURL.String() == "" {
30− p.ProfileURL = &url.URL{Scheme: "https",
31− Host: myUsaHost,
32− Path: "/api/v1/profile"}
33− }
34− if p.ValidateURL.String() == "" {
35− p.ValidateURL = &url.URL{Scheme: "https",
36− Host: myUsaHost,
37− Path: "/api/v1/tokeninfo"}
38− }
39− if p.Scope == "" {
40− p.Scope = "profile.email"
41− }
42− return &MyUsaProvider{ProviderData: p}
43−}
44−
45−func (p *MyUsaProvider) GetEmailAddress(s *SessionState) (string, error) {
46− req, err := http.NewRequest("GET",
47− p.ProfileURL.String()+"?access_token="+s.AccessToken, nil)
48− if err != nil {
49− log.Printf("failed building request %s", err)
50− return "", err
51− }
52− json, err := api.Request(req)
53− if err != nil {
54− log.Printf("failed making request %s", err)
55− return "", err
56− }
57− return json.Get("email").String()
58−}
providers/myusa_test.godeleted−141
@@ -1,141 +0,0 @@
1−package providers
2−
3−import (
4− "net/http"
5− "net/http/httptest"
6− "net/url"
7− "testing"
8−
9− "github.com/bmizerany/assert"
10−)
11−
12−func updateURL(url *url.URL, hostname string) {
13− url.Scheme = "http"
14− url.Host = hostname
15−}
16−
17−func testMyUsaProvider(hostname string) *MyUsaProvider {
18− p := NewMyUsaProvider(
19− &ProviderData{
20− ProviderName: "",
21− LoginURL: &url.URL{},
22− RedeemURL: &url.URL{},
23− ProfileURL: &url.URL{},
24− ValidateURL: &url.URL{},
25− Scope: ""})
26− if hostname != "" {
27− updateURL(p.Data().LoginURL, hostname)
28− updateURL(p.Data().RedeemURL, hostname)
29− updateURL(p.Data().ProfileURL, hostname)
30− updateURL(p.Data().ValidateURL, hostname)
31− }
32− return p
33−}
34−
35−func testMyUsaBackend(payload string) *httptest.Server {
36− path := "/api/v1/profile"
37− query := "access_token=imaginary_access_token"
38−
39− return httptest.NewServer(http.HandlerFunc(
40− func(w http.ResponseWriter, r *http.Request) {
41− url := r.URL
42− if url.Path != path || url.RawQuery != query {
43− w.WriteHeader(404)
44− } else {
45− w.WriteHeader(200)
46− w.Write([]byte(payload))
47− }
48− }))
49−}
50−
51−func TestMyUsaProviderDefaults(t *testing.T) {
52− p := testMyUsaProvider("")
53− assert.NotEqual(t, nil, p)
54− assert.Equal(t, "MyUSA", p.Data().ProviderName)
55− assert.Equal(t, "https://alpha.my.usa.gov/oauth/authorize",
56− p.Data().LoginURL.String())
57− assert.Equal(t, "https://alpha.my.usa.gov/oauth/token",
58− p.Data().RedeemURL.String())
59− assert.Equal(t, "https://alpha.my.usa.gov/api/v1/profile",
60− p.Data().ProfileURL.String())
61− assert.Equal(t, "https://alpha.my.usa.gov/api/v1/tokeninfo",
62− p.Data().ValidateURL.String())
63− assert.Equal(t, "profile.email", p.Data().Scope)
64−}
65−
66−func TestMyUsaProviderOverrides(t *testing.T) {
67− p := NewMyUsaProvider(
68− &ProviderData{
69− LoginURL: &url.URL{
70− Scheme: "https",
71− Host: "example.com",
72− Path: "/oauth/auth"},
73− RedeemURL: &url.URL{
74− Scheme: "https",
75− Host: "example.com",
76− Path: "/oauth/token"},
77− ProfileURL: &url.URL{
78− Scheme: "https",
79− Host: "example.com",
80− Path: "/oauth/profile"},
81− ValidateURL: &url.URL{
82− Scheme: "https",
83− Host: "example.com",
84− Path: "/oauth/tokeninfo"},
85− Scope: "profile"})
86− assert.NotEqual(t, nil, p)
87− assert.Equal(t, "MyUSA", p.Data().ProviderName)
88− assert.Equal(t, "https://example.com/oauth/auth",
89− p.Data().LoginURL.String())
90− assert.Equal(t, "https://example.com/oauth/token",
91− p.Data().RedeemURL.String())
92− assert.Equal(t, "https://example.com/oauth/profile",
93− p.Data().ProfileURL.String())
94− assert.Equal(t, "https://example.com/oauth/tokeninfo",
95− p.Data().ValidateURL.String())
96− assert.Equal(t, "profile", p.Data().Scope)
97−}
98−
99−func TestMyUsaProviderGetEmailAddress(t *testing.T) {
100− b := testMyUsaBackend("{\"email\": \"michael.bland@gsa.gov\"}")
101− defer b.Close()
102−
103− b_url, _ := url.Parse(b.URL)
104− p := testMyUsaProvider(b_url.Host)
105−
106− session := &SessionState{AccessToken: "imaginary_access_token"}
107− email, err := p.GetEmailAddress(session)
108− assert.Equal(t, nil, err)
109− assert.Equal(t, "michael.bland@gsa.gov", email)
110−}
111−
112−// Note that trying to trigger the "failed building request" case is not
113−// practical, since the only way it can fail is if the URL fails to parse.
114−func TestMyUsaProviderGetEmailAddressFailedRequest(t *testing.T) {
115− b := testMyUsaBackend("unused payload")
116− defer b.Close()
117−
118− b_url, _ := url.Parse(b.URL)
119− p := testMyUsaProvider(b_url.Host)
120−
121− // We'll trigger a request failure by using an unexpected access
122− // token. Alternatively, we could allow the parsing of the payload as
123− // JSON to fail.
124− session := &SessionState{AccessToken: "unexpected_access_token"}
125− email, err := p.GetEmailAddress(session)
126− assert.NotEqual(t, nil, err)
127− assert.Equal(t, "", email)
128−}
129−
130−func TestMyUsaProviderGetEmailAddressEmailNotPresentInPayload(t *testing.T) {
131− b := testMyUsaBackend("{\"foo\": \"bar\"}")
132− defer b.Close()
133−
134− b_url, _ := url.Parse(b.URL)
135− p := testMyUsaProvider(b_url.Host)
136−
137− session := &SessionState{AccessToken: "imaginary_access_token"}
138− email, err := p.GetEmailAddress(session)
139− assert.NotEqual(t, nil, err)
140− assert.Equal(t, "", email)
141−}
providers/providers.go−2
@@ -18,8 +18,6 @@ type Provider interface {
1818
1919func New(provider string, p *ProviderData) Provider {
2020 switch provider {
21− case "myusa":
22− return NewMyUsaProvider(p)
2321 case "linkedin":
2422 return NewLinkedInProvider(p)
2523 case "facebook":