Skip to content

Commit

Permalink
refactor add check header token
Browse files Browse the repository at this point in the history
  • Loading branch information
zelhat committed Jan 11, 2024
1 parent bf2ab6e commit ffa39bd
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions internal/util/jwt.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package util

import (
"fmt"
"time"

"github.com/golang-jwt/jwt/v4"
Expand Down Expand Up @@ -35,6 +36,9 @@ func CreateToken(username string, userid uint64) (string, error) {
func GetUser(tokenString string) string {
userClaim := &UserClaim{}
token, err := jwt.ParseWithClaims(tokenString, userClaim, func(token *jwt.Token) (interface{}, error) {
if _, ok := token.Method.(*jwt.SigningMethodHMAC); !ok {
return nil, fmt.Errorf("unexpected signing method: %v", token.Header["alg"])
}
return []byte(secretKey), nil
})
if err != nil {
Expand Down

0 comments on commit ffa39bd

Please sign in to comment.