如何使api资源管理器oauth2适用于端点? (作用域https://www.googleapis.com/auth/userinfo.email)
func (gs *GreetingService) Store(r *http.Request, req *Request, resp *Response) error {
c := appengine.NewContext(r)
u := user.Current(c)
if u != nil {c.Infof("Hello, %v\n", u)}
if u != nil {fmt.Printf("Hello, %v\n", u)}
}
u
始终为零,在Java中,我必须添加类似的内容才能使其正常工作。@Api(name = "rest1",
version = "0",
scopes = {Id.EMAIL_SCOPE},
clientIds = {Id.WEB_CLIENT_ID, Id.ANDROID_CLIENT_IDd, Id.ANDROID_CLIENT_IDr, Id.EXPLORER_ID},
audiences = {Id.ANDROID_AUDIENCE})
您如何使其适用于端点?
编辑
h!我发现此http://godoc.org/github.com/crhym3/go-endpoints/endpoints#CurrentBearerTokenUser PS是golang的API_EXPLORER_CLIENT_ID是什么?
doh2!
http://godoc.org/github.com/crhym3/go-endpoints/endpoints#pkg-constants
最佳答案
func (gs *GreetingService) Store(r *http.Request, req *Request, resp *Response) error {
c := endpoints.NewContext(r)
u, err := endpoints.CurrentBearerTokenUser(c, []string{"https://www.googleapis.com/auth/userinfo.email"}, []string{"...apps.googleusercontent.com",endpoints.ApiExplorerClientId})
if err != nil {return err}
c.Infof("-------------------")
if u != nil {c.Infof("Hello, %v\n", u)}
c.Infof("-------------------")
}
关于google-app-engine - go-endpoints oauth2用户始终为零,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/20733872/