gtsocial-umbx

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit d2a85f2f5fcadf8366ee611d7f10b3767277817b
parent fce3ba63825f563b2ddb24fcf44847eef3547b5b
Author: kim (grufwub) <grufwub@gmail.com>
Date:   Wed,  8 Sep 2021 20:46:08 +0100

handle oauth token scope, fix user.SigninCount + token.UserID

Signed-off-by: kim (grufwub) <grufwub@gmail.com>

Diffstat:
Minternal/api/client/auth/token.go | 4++++
Minternal/gtsmodel/token.go | 2+-
Minternal/gtsmodel/user.go | 2+-
3 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/internal/api/client/auth/token.go b/internal/api/client/auth/token.go @@ -31,6 +31,7 @@ type tokenBody struct { Code *string `form:"code" json:"code" xml:"code"` GrantType *string `form:"grant_type" json:"grant_type" xml:"grant_type"` RedirectURI *string `form:"redirect_uri" json:"redirect_uri" xml:"redirect_uri"` + Scope *string `form:"scope" json:"scope" xml:"scope"` } // TokenPOSTHandler should be served as a POST at https://example.org/oauth/token @@ -58,6 +59,9 @@ func (m *Module) TokenPOSTHandler(c *gin.Context) { if form.RedirectURI != nil { c.Request.Form.Set("redirect_uri", *form.RedirectURI) } + if form.Scope != nil { + c.Request.Form.Set("scope", *form.Scope) + } } if err := m.server.HandleTokenRequest(c.Writer, c.Request); err != nil { diff --git a/internal/gtsmodel/token.go b/internal/gtsmodel/token.go @@ -26,7 +26,7 @@ type Token struct { CreatedAt time.Time `validate:"-" bun:"type:timestamp,nullzero,notnull,default:current_timestamp"` // when was item created UpdatedAt time.Time `validate:"-" bun:"type:timestamp,nullzero,notnull,default:current_timestamp"` // when was item last updated ClientID string `validate:"required,ulid" bun:"type:CHAR(26),nullzero,notnull"` // ID of the client who owns this token - UserID string `validate:"required,ulid" bun:"type:CHAR(26),nullzero,notnull"` // ID of the user who owns this token + UserID string `validate:"required,ulid" bun:"type:CHAR(26),nullzero"` // ID of the user who owns this token RedirectURI string `validate:"required,uri" bun:",nullzero,notnull"` // Oauth redirect URI for this token Scope string `validate:"required" bun:",nullzero,notnull"` // Oauth scope Code string `validate:"-" bun:",pk,nullzero,notnull,default:''"` // Code, if present diff --git a/internal/gtsmodel/user.go b/internal/gtsmodel/user.go @@ -38,7 +38,7 @@ type User struct { CurrentSignInIP net.IP `validate:"-" bun:",nullzero"` // What's the most recent IP of this user LastSignInAt time.Time `validate:"-" bun:"type:timestamp,nullzero"` // When did this user last sign in? LastSignInIP net.IP `validate:"-" bun:",nullzero"` // What's the previous IP of this user? - SignInCount int `validate:"min=0" bun:",nullzero,notnull,default:0"` // How many times has this user signed in? + SignInCount int `validate:"min=0" bun:",notnull,default:0"` // How many times has this user signed in? InviteID string `validate:"omitempty,ulid" bun:"type:CHAR(26),nullzero"` // id of the user who invited this user (who let this joker in?) ChosenLanguages []string `validate:"-" bun:",nullzero"` // What languages does this user want to see? FilteredLanguages []string `validate:"-" bun:",nullzero"` // What languages does this user not want to see?