我想使用golang客户端对Google App Engine上受保护的应用程序进行身份验证(Google帐户),在app.yaml中指定login: required或login: admin在app.yaml中指定.
首先,我编写了一个简单的OAuth2离线访问客户端,但它根本不起作用 - 服务器只是将客户端重定向到Google帐户的登录页面.我尝试过使用各种Google API范围,目前没有运气.
package main
import (
"context"
"fmt"
"io"
"log"
"os"
"golang.org/x/oauth2"
"golang.org/x/oauth2/google"
)
const (
AppURL = "https://login-requried-app.appspot.com"
AuthClientID = "....."
AuthClientSecret = "....."
AuthRedirectURL = "urn:ietf:wg:oauth:2.0:oob"
AuthScope = "https://www.googleapis.com/auth/cloud-platform"
)
func main() {
ctx := context.Background()
conf := &oauth2.Config{
ClientID: AuthClientID,
ClientSecret: AuthClientSecret,
Endpoint: google.Endpoint,
RedirectURL: AuthRedirectURL,
Scopes: []string{AuthScope},
}
url := conf.AuthCodeURL("state", oauth2.AccessTypeOffline)
fmt.Printf("Visit the URL for the auth dialog: %v\n", url)
fmt.Printf("Enter authentication code: ") …Run Code Online (Sandbox Code Playgroud)