英文:
Google App Engine with GoLang "permission denied" error on Oauth2 autentification
问题
Oauth2认证库
在本地主机上运行良好,但上传到Google App Engine后崩溃
当执行上述代码的第250行时
r, err := (&http.Client{Transport: t.transport()}).PostForm(t.TokenURL, v)
错误响应是“权限被拒绝”
英文:
Oauth2 autentification library
Works well on the localhost but crashes when is uploaded to the Google App Engine
When it does the line 250 of the above code
r, err := (&http.Client{Transport: t.transport()}).PostForm(t.TokenURL, v)
The error response is "permission denied"
答案1
得分: 6
从api.go文档中:
> 由于Google App Engine URL Fetch API需要每个请求一个上下文,所以您必须在HTTP处理程序中使用plus.Service。该包提供了WithNoAuthPlus和WithOAuthPlus函数,您可以使用它们来包装您的HTTP处理程序,以便为它们提供完全初始化的plus.Services。
示例:
c := appengine.NewContext(r)
trans := &oauth.Transport{
Config: oauthConfig,
Transport: &urlfetch.Transport{Context: c},
}
trans.Exchange(code)
resp, err := trans.Client().Get(profileInfoURL)
英文:
From the api.go documentation :
> Since the Google App Engine URL Fetch API requires a per-request
> context, you must use the *plus.Service from within an HTTP handler.
> This package provides the WithNoAuthPlus and WithOAuthPlus functions
> which you can use to wrap your HTTP handlers to provide them with
> fully initialized *plus.Services.
Example:
c := appengine.NewContext(r)
trans := &oauth.Transport{
Config: oauthConfig,
Transport: &urlfetch.Transport{Context: c},
}
trans.Exchange(code)
resp, err := trans.Client().Get(profileInfoURL)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论