Skip to content

Commit

Permalink
Improve error reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
benpate committed Aug 29, 2024
1 parent eba15c4 commit ef23197
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion handler/mastodon/authorizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
// JWT token was created for a particular OAuth client and is not a regular User token
func Authorizer(serverFactory *server.Factory) toot.Authorizer[model.Authorization] {

const location = "handler.mastodon_Authorization"
const location = "handler.mastodon.Authorizater"

return func(request *http.Request) (model.Authorization, error) {

Expand Down
10 changes: 8 additions & 2 deletions service/jwt.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,20 @@ func (service *JWT) ParseString(tokenString string) (*jwt.Token, error) {

const location = "service.JWT.ParseString"

claims := model.NewAuthorization()
// RULE: JWT token must not be empty
if tokenString == "" {
return nil, derp.NewBadRequestError(location, "JWT token is empty")
}

// Try to parse the JWT token
claims := model.NewAuthorization()
result, err := jwt.ParseWithClaims(tokenString, &claims, service.FindKey, jwt.WithValidMethods([]string{"HS256", "HS384", "HS512"}))

if err != nil {
return nil, derp.Wrap(err, location, "Error parsing JWT token")
return nil, derp.Wrap(err, location, "Error parsing JWT token", tokenString)
}

// Success.
return result, nil
}

Expand Down

0 comments on commit ef23197

Please sign in to comment.