dongqiangse6623 2019-09-18 05:53
浏览 133

无法使用oauth2获取令牌错误以获取amazondrive的身份验证代码

I am trying to access amazon drive through a command line application. I have also created a security profile on amazon and enabled login with amazon. The main function calls the Setup() function.

package main

import (
    "fmt"

    "github.com/fatih/color"
    "github.com/toqueteos/webbrowser"

    "golang.org/x/oauth2"
)

type ACDriveStore struct {
    Config     oauth2.Config `json:"oauth_config"`
    OAuthToken oauth2.Token  `json:"oauth_token"`
}

func (acd *ACDriveStore) Setup() bool {
    config := receiveConfig()

    token, err := getACDriveTokenFromWeb(config)
    if err != nil {
        color.Red("Unable to get client token: %v", err)
        return false
    }

    acd.OAuthToken = *token

    return false
}

func getACDriveTokenFromWeb(config *oauth2.Config) (*oauth2.Token, error) {
    authURL := config.AuthCodeURL("go-acd", oauth2.AccessTypeOffline)
    webbrowser.Open(authURL)

    color.Yellow("Enter Auth Code: ")

    var authCode string
    if _, err := fmt.Scan(&authCode); err != nil {
        color.Red("Unable to read authentication code %v", err)
        return nil, err
    }

    tok, err := config.Exchange(oauth2.NoContext, authCode)
    if err != nil {
        color.Red("Unable to retrieve token from web %v", err)
        return tok, err
    }

    return tok, nil
}

func receiveConfig() *oauth2.Config {
    var appKey, appSecret string

    appKey, appSecret = AmazonDriveClientKey, AmazonDriveClientSecret

    return &oauth2.Config{
        ClientID:     appKey,
        ClientSecret: appSecret,
        Endpoint: oauth2.Endpoint{
            AuthURL:  "https://www.amazon.com/ap/oa",
            TokenURL: "https://api.amazon.com/auth/o2/token",
        },
        RedirectURL: "https://go-acd.appspot.com/oauth",
        Scopes:      []string{"clouddrive:read", "clouddrive:write"},
    }
}

But I am getting this error.

oauth2: cannot fetch token: 400 Bad Request Response: {"error":"invalid_request","error_description":"The request is missing a required parameter : code"} null

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥500 火焰左右视图、视差(基于双目相机)
    • ¥100 set_link_state
    • ¥15 虚幻5 UE美术毛发渲染
    • ¥15 CVRP 图论 物流运输优化
    • ¥15 Tableau online 嵌入ppt失败
    • ¥100 支付宝网页转账系统不识别账号
    • ¥15 基于单片机的靶位控制系统
    • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
    • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
    • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本