Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用go在OAuth中编写重定向URL_Url_Go_Oauth 2.0 - Fatal编程技术网

如何使用go在OAuth中编写重定向URL

如何使用go在OAuth中编写重定向URL,url,go,oauth-2.0,Url,Go,Oauth 2.0,上面的代码是我的代码中的init函数部分RedirectURL:“http://127.0.0.1:3000/auth“ 使用localhost链接,但是如果我使用heruko部署我的站点,会发生什么情况?如果是,127.0.0.1不应该更改吗?如果是,我应该如何更改它?Heroku建议对大多数配置使用环境变量,因此您可以使用os包从环境中检索重定向url func init() { file, err := ioutil.ReadFile("./creds.json") if

上面的代码是我的代码中的init函数部分
RedirectURL:“http://127.0.0.1:3000/auth“

使用localhost链接,但是如果我使用heruko部署我的站点,会发生什么情况?如果是,127.0.0.1不应该更改吗?如果是,我应该如何更改它?Heroku建议对大多数配置使用环境变量,因此您可以使用
os
包从环境中检索重定向url

func init() {
    file, err := ioutil.ReadFile("./creds.json")
    if err != nil {
        log.Printf("File error: %v\n", err)
        os.Exit(1)
    }
    json.Unmarshal(file, &cred)

    conf = &oauth2.Config{
        ClientID:     cred.Cid,
        ClientSecret: cred.Csecret,
        RedirectURL:  "http://127.0.0.1:3000/auth",
        Scopes: []string{
            "https://www.googleapis.com/auth/userinfo.email", // You have to select your own scope from here -> https://developers.google.com/identity/protocols/googlescopes#google_sign-in
            "https://www.googleapis.com/auth/calendar", "https://www.googleapis.com/auth/calendar.readonly",
        },
        Endpoint: google.Endpoint,
    }
}
然后在本地计算机上设置一个环境变量,如下所示:

func init() {
    redirURL := os.Getenv("OAUTH_REDIRECT_URL")

    file, err := ioutil.ReadFile("./creds.json")
    if err != nil {
        log.Printf("File error: %v\n", err)
        os.Exit(1)
    }
    json.Unmarshal(file, &cred)

    conf = &oauth2.Config{
        ClientID:     cred.Cid,
        ClientSecret: cred.Csecret,
        RedirectURL:  redirURL,
        Scopes: []string{
            "https://www.googleapis.com/auth/userinfo.email", // You have to select your own scope from here -> https://developers.google.com/identity/protocols/googlescopes#google_sign-in
            "https://www.googleapis.com/auth/calendar", "https://www.googleapis.com/auth/calendar.readonly",
        },
        Endpoint: google.Endpoint,
    }
}
在heroku dyno上,将其设置为需要重定向到的值

export OAUTH_REDIRECT_URL=http://127.0.0.1:3000/auth