Google App Engine使用GoLang时出现“权限被拒绝”错误的Oauth2身份验证。

huangapple go评论68阅读模式
英文:

Google App Engine with GoLang "permission denied" error on Oauth2 autentification

问题

Oauth2认证库
在本地主机上运行良好,但上传到Google App Engine后崩溃

oauth.go

当执行上述代码的第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

oauth.go

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)

huangapple
  • 本文由 发表于 2012年6月27日 20:26:49
  • 转载请务必保留本文链接:https://go.coder-hub.com/11226181.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定