M bearer.go => bearer.go +3 -11
@@ 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
M go.mod => go.mod +1 -0
@@ 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
)
M go.sum => go.sum +2 -0
@@ 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=
M routes.go => routes.go +2 -1
@@ 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)