feat: implement create&delete user access token api

This commit is contained in:
Steven
2023-08-06 20:53:45 +08:00
parent ad988575b3
commit a90279221c
10 changed files with 1085 additions and 265 deletions

View File

@ -38,11 +38,6 @@ const (
UserIDContextKey ContextKey = iota
)
type claimsMessage struct {
Name string `json:"name"`
jwt.RegisteredClaims
}
// GRPCAuthInterceptor is the auth interceptor for gRPC server.
type GRPCAuthInterceptor struct {
Store *store.Store
@ -93,7 +88,7 @@ func (in *GRPCAuthInterceptor) authenticate(ctx context.Context, accessTokenStr
if accessTokenStr == "" {
return 0, status.Errorf(codes.Unauthenticated, "access token not found")
}
claims := &claimsMessage{}
claims := &auth.ClaimsMessage{}
_, err := jwt.ParseWithClaims(accessTokenStr, claims, func(t *jwt.Token) (any, error) {
if t.Method.Alg() != jwt.SigningMethodHS256.Name {
return nil, status.Errorf(codes.Unauthenticated, "unexpected access token signing method=%v, expect %v", t.Header["alg"], jwt.SigningMethodHS256)