Skip to content

Commit 1b35698

Browse files
author
thisisaaronland
committed
update to reflect changes in aaronland/go-http-crumb v0.0.6
1 parent e2a58d0 commit 1b35698

File tree

5 files changed

+29
-22
lines changed

5 files changed

+29
-22
lines changed

flags/oauth2.go

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import (
1010
"github.com/sfomuseum/go-flags"
1111
"github.com/sfomuseum/go-http-oauth2"
1212
goog_oauth2 "golang.org/x/oauth2"
13+
"net/url"
14+
"strconv"
1315
"strings"
1416
"sync"
1517
)
@@ -136,16 +138,14 @@ func OAuth2OptionsWithFlagSet(ctx context.Context, fs *flag.FlagSet) (*oauth2.Op
136138
cookie_uri = fmt.Sprintf("encrypted://?name=%s&secret=%s&salt=%s", name, secret, salt)
137139
}
138140

139-
signin_crumb, err := NewOAuth2CrumbConfig("signin", 120)
141+
signin_crumb, err := NewOAuth2Crumb(ctx, "signin", 120)
140142

141143
if err != nil {
142144
oauth2_err = err
143145
return
144146
}
145147

146-
// not sure about this (20204016/thisisaaronland)
147-
148-
signout_crumb, err := NewOAuth2CrumbConfig("signout", 3600)
148+
signout_crumb, err := NewOAuth2Crumb(ctx, "signout", 3600)
149149

150150
if err != nil {
151151
oauth2_err = err
@@ -174,7 +174,7 @@ func OAuth2OptionsWithFlagSet(ctx context.Context, fs *flag.FlagSet) (*oauth2.Op
174174
return oauth2_opts, nil
175175
}
176176

177-
func NewOAuth2CrumbConfig(key string, ttl int64) (*crumb.CrumbConfig, error) {
177+
func NewOAuth2Crumb(ctx context.Context, key string, ttl int64) (crumb.Crumb, error) {
178178

179179
r_opts := random.DefaultOptions()
180180
r_opts.AlphaNumeric = true
@@ -192,15 +192,16 @@ func NewOAuth2CrumbConfig(key string, ttl int64) (*crumb.CrumbConfig, error) {
192192
return nil, err
193193
}
194194

195-
separator := ":"
195+
str_ttl := strconv.FormatInt(ttl, 10)
196196

197-
cfg := &crumb.CrumbConfig{
198-
Extra: extra,
199-
Separator: separator,
200-
Secret: secret,
201-
TTL: ttl,
202-
Key: key,
203-
}
197+
params := url.Values{}
198+
params.Set("extra", extra)
199+
params.Set("separator", ":")
200+
params.Set("secret", secret)
201+
params.Set("ttl", str_ttl)
202+
params.Set("key", key)
203+
204+
crumb_uri := fmt.Sprintf("encrypted://?%s", params.Encode())
204205

205-
return cfg, nil
206+
return crumb.NewCrumb(ctx, crumb_uri)
206207
}

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ module github.com/sfomuseum/go-http-oauth2
33
go 1.12
44

55
require (
6-
github.com/aaronland/go-http-cookie v0.1.0
7-
github.com/aaronland/go-http-crumb v0.0.5
6+
github.com/aaronland/go-http-cookie v0.2.0
7+
github.com/aaronland/go-http-crumb v0.0.6
88
github.com/aaronland/go-http-sanitize v0.0.4
99
github.com/aaronland/go-string v0.1.2
1010
github.com/sfomuseum/go-flags v0.0.2

go.sum

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@ github.com/aaronland/go-http-cookie v0.0.2 h1:PKJpfBL/w2ADg9sFyiOoPFhFF/QAFQYe2L
33
github.com/aaronland/go-http-cookie v0.0.2/go.mod h1:KF6QghGeR7w7oNqRgvc9ITFQc+iV5N9Y2SbroNkxEPY=
44
github.com/aaronland/go-http-cookie v0.1.0 h1:ToMGm/RAFEgdGUMKJiMhMCfGiQUGAlUy5gcttPjVrMQ=
55
github.com/aaronland/go-http-cookie v0.1.0/go.mod h1:fGP679ZUdWY+ISTL26BcHG6q7T8GT7rklpZJ/eHC7yo=
6+
github.com/aaronland/go-http-cookie v0.2.0 h1:DXJ4jJ7lRwOGP1rUn68K3n24r6dGOO/3PdfoKBlMxe0=
7+
github.com/aaronland/go-http-cookie v0.2.0/go.mod h1:fGP679ZUdWY+ISTL26BcHG6q7T8GT7rklpZJ/eHC7yo=
68
github.com/aaronland/go-http-crumb v0.0.5 h1:ZhBkvWUW9wsw+KYnOu0sHAeRpsfY9kj0wh7yA8qGA0M=
79
github.com/aaronland/go-http-crumb v0.0.5/go.mod h1:tzp6zHKE/pojVXQhcS1J5x5qQkhhxOTvJS2N7S1VVuY=
10+
github.com/aaronland/go-http-crumb v0.0.6 h1:R+hGU1SdkKxLqKIuabBwXpemo7VqFaCVYg4YK13JOnw=
11+
github.com/aaronland/go-http-crumb v0.0.6/go.mod h1:mf4QGr+5Mraf6ta1CwLJHSe31yWgDgmM8OxcLilnrpY=
812
github.com/aaronland/go-http-rewrite v0.0.4 h1:lI8cDF/nINjuSPrYpwvlJLa1cC32h1nvmBwRRHs9sow=
913
github.com/aaronland/go-http-rewrite v0.0.4/go.mod h1:g62jjXpsArD0lzJLs9bVLR9Locdt3f4OmqFkkJL2rQU=
1014
github.com/aaronland/go-http-sanitize v0.0.1/go.mod h1:qUi4rzUPcpMntpUFnHK00yQI5vd/Q7x9MFYwX91/ygI=
@@ -38,12 +42,15 @@ golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73r
3842
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
3943
golang.org/x/net v0.0.0-20190613194153-d28f0bde5980 h1:dfGZHvZk057jK2MCeWus/TowKpJ8y4AmooUzdBSR9GU=
4044
golang.org/x/net v0.0.0-20190613194153-d28f0bde5980/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
45+
golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e h1:3G+cUijn7XD+S4eJFddp53Pv7+slrESplyjG25HgL+k=
46+
golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
4147
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d h1:TzXSXBo42m9gQenoE3b9BGiEpg5IG2JkU5FkPIawgtw=
4248
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
4349
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
4450
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
4551
golang.org/x/sys v0.0.0-20190412213103-97732733099d h1:+R4KGOnez64A81RvjARKc4UT5/tI9ujCIVX+P5KiHuI=
4652
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
53+
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
4754
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
4855
google.golang.org/appengine v1.4.0 h1:/wp5JvzpHIxhs/dumFmF7BXTf3Z+dd4uXta4kVyO508=
4956
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=

oauth2.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ type Options struct {
99
AuthURL string
1010
CookieURI string
1111
Config *oauth2.Config
12-
AuthCrumb *crumb.CrumbConfig
13-
UnAuthCrumb *crumb.CrumbConfig
12+
AuthCrumb crumb.Crumb
13+
UnAuthCrumb crumb.Crumb
1414
}

www/cookie.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"encoding/json"
66
"errors"
77
"github.com/aaronland/go-http-cookie"
8-
"github.com/aaronland/go-http-crumb"
98
"github.com/aaronland/go-http-sanitize"
109
"github.com/sfomuseum/go-http-oauth2"
1110
goog_oauth2 "golang.org/x/oauth2"
@@ -88,7 +87,7 @@ func OAuth2TokenCookieAuthorizeHandler(opts *oauth2.Options) (http.Handler, erro
8887
redir_url := redir.String()
8988
cfg.RedirectURL = redir_url
9089

91-
state, err := crumb.GenerateCrumb(opts.AuthCrumb, req)
90+
state, err := opts.AuthCrumb.Generate(req)
9291

9392
if err != nil {
9493
http.Error(rsp, err.Error(), http.StatusInternalServerError)
@@ -139,7 +138,7 @@ func OAuth2AccessTokenCookieHandler(opts *oauth2.Options) (http.Handler, error)
139138
return
140139
}
141140

142-
ok, err := crumb.ValidateCrumb(opts.AuthCrumb, req, state)
141+
ok, err := opts.AuthCrumb.Validate(req, state)
143142

144143
if err != nil {
145144
http.Error(rsp, err.Error(), http.StatusInternalServerError)
@@ -234,7 +233,7 @@ func OAuth2RemoveAccessTokenCookieHandler(opts *oauth2.Options) (http.Handler, e
234233
return
235234
}
236235

237-
ok, err := crumb.ValidateCrumb(opts.UnAuthCrumb, req, crumb_var)
236+
ok, err := opts.UnAuthCrumb.Validate(req, crumb_var)
238237

239238
if err != nil {
240239
http.Error(rsp, err.Error(), http.StatusInternalServerError)

0 commit comments

Comments
 (0)