dongxin8392 2013-12-22 20:42
浏览 38
已采纳

go-endpoints oauth2用户始终为零

How do you make the api explorer oauth2 work for go-endpoints? (scope 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
", u)}
    if u != nil {fmt.Printf("Hello, %v
", u)}
}

u is always nil, in java I had to add something like this to make it work.

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

How do you make it work for go-endpoints?

EDIT

doh! I found this http://godoc.org/github.com/crhym3/go-endpoints/endpoints#CurrentBearerTokenUser PS what is the API_EXPLORER_CLIENT_ID for golang?

doh2! http://godoc.org/github.com/crhym3/go-endpoints/endpoints#pkg-constants

  • 写回答

1条回答 默认 最新

  • dongsong73032 2013-12-22 22:37
    关注
    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
    ", u)}
        c.Infof("-------------------")
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图