From 0321b8ce3a8d16467aa362b99115d709313aa25c Mon Sep 17 00:00:00 2001 From: Peter Sanchez Date: Sat, 10 Feb 2024 08:28:20 -0600 Subject: [PATCH] Removing local contians function for slices module --- bearer.go | 14 +++----------- go.mod | 1 + go.sum | 2 ++ routes.go | 3 ++- 4 files changed, 8 insertions(+), 12 deletions(-) diff --git a/bearer.go b/bearer.go index a279601..7dc1824 100644 --- a/bearer.go +++ b/bearer.go @@ -8,6 +8,7 @@ import ( "time" "git.sr.ht/~sircmpwn/go-bare" + "golang.org/x/exp/slices" "netlandish.com/x/gobwebs" "netlandish.com/x/gobwebs/crypto" ) @@ -53,7 +54,7 @@ type BearerToken struct { func (b *BearerToken) Encode(ctx context.Context) string { kw := crypto.KWForContext(ctx) if b.Type == "" { - b.Type = "OAUTH2" + b.Type = TypeOAuth2 } plain, err := bare.Marshal(b) if err != nil { @@ -191,7 +192,7 @@ func (g *Grants) Encode() string { func (g *Grants) Validate(scopes []string) []string { var errors []string for k := range g.grants { - if !contains(scopes, k) { + if !slices.Contains(scopes, k) { errors = append(errors, fmt.Sprintf("Invalid scope: %s", k)) } } @@ -207,15 +208,6 @@ func (g *Grants) List() []string { return grants } -func contains(values []string, str string) bool { - for _, v := range values { - if v == str { - return true - } - } - return false -} - // TokenUser wrapper for gobwebs.User and token grants type TokenUser struct { User gobwebs.User diff --git a/go.mod b/go.mod index 48e268f..0b40f7b 100644 --- a/go.mod +++ b/go.mod @@ -7,6 +7,7 @@ require ( github.com/Masterminds/squirrel v1.5.4 github.com/labstack/echo/v4 v4.11.3 github.com/segmentio/ksuid v1.0.4 + golang.org/x/exp v0.0.0-20240112132812-db7319d0e0e3 netlandish.com/x/gobwebs v0.0.0-20231224184438-126f0f16331b ) diff --git a/go.sum b/go.sum index 5e8aa46..9374cb5 100644 --- a/go.sum +++ b/go.sum @@ -344,6 +344,8 @@ golang.org/x/exp v0.0.0-20191227195350-da58074b4299/go.mod h1:2RIsYlXP63K8oxa1u0 golang.org/x/exp v0.0.0-20200119233911-0405dc783f0a/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4= golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EHIKF9dgMWnmCNThgcyBT1FY9mM= golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU= +golang.org/x/exp v0.0.0-20240112132812-db7319d0e0e3 h1:hNQpMuAJe5CtcUqCXaWga3FHu+kQvCqcsoVaQgSV60o= +golang.org/x/exp v0.0.0-20240112132812-db7319d0e0e3/go.mod h1:idGWGoKP1toJGkd5/ig9ZLuPcZBC3ewk7SzmH0uou08= golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= diff --git a/routes.go b/routes.go index 817a4ac..bf0be9f 100644 --- a/routes.go +++ b/routes.go @@ -16,6 +16,7 @@ import ( sq "github.com/Masterminds/squirrel" "github.com/labstack/echo/v4" + "golang.org/x/exp/slices" "netlandish.com/x/gobwebs" "netlandish.com/x/gobwebs/auth" "netlandish.com/x/gobwebs/database" @@ -419,7 +420,7 @@ func (s *Service) AuthorizePOST(c echo.Context) error { // XXX csrf shouldn't be hard coded here skip := []string{"accept", "client_id", "redirect_uri", "state", "csrf"} for grant := range params { - if contains(skip, grant) { + if slices.Contains(skip, grant) { continue } subgrants = append(subgrants, grant) -- 2.43.0