如何让api explorer oauth2为go-endpoints工作? (范围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})
如何让它适用于端点?
修改
DOH!我发现这个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
答案 0 :(得分:1)
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("-------------------")
}