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-zero中集成go-oauth2后,如何跨服务验证token #248

Open
tgy3300 opened this issue Jul 25, 2023 · 1 comment
Open

我在go-zero中集成go-oauth2后,如何跨服务验证token #248

tgy3300 opened this issue Jul 25, 2023 · 1 comment

Comments

@tgy3300
Copy link

tgy3300 commented Jul 25, 2023

我使用最新版的go-zero开发了go微服务,服务如下:
account-api
admin-api

go-oauth2是集成在account-api端的,按照官方的文档已经成功集成,现在的问题是,
在前端(vue开发的前端)访问account-api/account/info接口

这个接口使用下面的代码验证前端携带的token,可以正常验证并通过

token, err := svcCtx.Oauth2Res.CheckToken(w, r)
		if err != nil {
			return
		}

CheckToken的封装是根据https://github.com/llaoj/oauth2nsso/blob/master/main.go#L273C8-L273C8进行的

现在在前端使用同样的请求头请求admin-api/system/info接口,接口使用同样的代码

token, err := svcCtx.Oauth2Res.CheckToken(w, r)
		if err != nil {
			return
		}

报invalid access token错误

如何解决跨服务验证token,还请指点

@daifuyang
Copy link

把oauth当请求服务。然后所有的都走api中间件验证就可以了

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

2 participants