Skip to content

Commit

Permalink
Add cast error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
osamingo committed Sep 1, 2022
1 parent f8fbc53 commit d482642
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 5 additions & 1 deletion examples/http-example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ func (c *CustomClaimsExample) Validate(ctx context.Context) error {
}

var handler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
claims, _ := r.Context().Value(jwtmiddleware.ContextKey{}).(*validator.ValidatedClaims)
claims, ok := r.Context().Value(jwtmiddleware.ContextKey{}).(*validator.ValidatedClaims)
if !ok {
http.Error(w, "failed to get validated claims", http.StatusInternalServerError)
return
}

payload, err := json.Marshal(claims)
if err != nil {
Expand Down
6 changes: 5 additions & 1 deletion examples/http-jwks-example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ import (
)

var handler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
claims, _ := r.Context().Value(jwtmiddleware.ContextKey{}).(*validator.ValidatedClaims)
claims, ok := r.Context().Value(jwtmiddleware.ContextKey{}).(*validator.ValidatedClaims)
if !ok {
http.Error(w, "failed to get validated claims", http.StatusInternalServerError)
return
}

payload, err := json.Marshal(claims)
if err != nil {
Expand Down

0 comments on commit d482642

Please sign in to comment.