Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[go-micro/auth.Inspect()] Is this function working? #2674

Open
thuc201995 opened this issue Nov 20, 2023 · 2 comments
Open

[go-micro/auth.Inspect()] Is this function working? #2674

thuc201995 opened this issue Nov 20, 2023 · 2 comments

Comments

@thuc201995
Copy link

Please help!!!!!
I don't know how to use it, It doesn't inspect anything from the token.

Inspect(token string) (*Account, error)

https://github.com/go-micro/examples/blob/758a9e786e6ae78456bf54bcd56d6bf672534e30/auth/auth.go#L57C4-L57C4

@jochumdev
Copy link
Member

@Davincible

@jochumdev jochumdev changed the title Is this function working? [go-micro/auth.Inspect()] Is this function working? Nov 26, 2023
@hhniao
Copy link

hhniao commented Dec 28, 2023

@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
		}
	}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants