Closed thuc201995 closed 2 months ago
@Davincible
@thuc201995 this code maby helpful for you.
type JwtAuth struct {
auth.Auth
}
func (a JwtAuth) Inspect(token string) (*auth.Account, error) {
conf := config.Config()
claims, err := Jwt{}.Validation(token, conf.JWT.Secret, false)
if err != nil {
return nil, err
}
id, _ := claims.GetSubject()
return &auth.Account{
ID: id,
}, nil
}
func NewAuthWrapper(service micro.Service) server.HandlerWrapper {
return func(h server.HandlerFunc) server.HandlerFunc {
return func(ctx context.Context, req server.Request, rsp interface{}) error {
... the rest code
a := service.Options().Auth
acc, err := a.Inspect(token)
... the rest code
}
}
}
Please help!!!!! I don't know how to use it, It doesn't inspect anything from the token.
https://github.com/go-micro/go-micro/blob/7392705af8122a66d00d51582693d0cc05ce1eee/auth/auth.go#L35 https://github.com/go-micro/examples/blob/758a9e786e6ae78456bf54bcd56d6bf672534e30/auth/auth.go#L57C4-L57C4