douluoxiao2286 2018-03-14 08:02
浏览 407

ebay API客户端凭据授权

I want to implement an Ebay Browse API client credentials grant flow in Go using the oauth2 package. Here is my conf struct:

    conf := clientcredentials.Config{
        ClientID:     "My Client ID",
        ClientSecret: "My client Secret",
        Scopes:       []string{"https://api.ebay.com/oauth/api_scope"},
        TokenURL:     "https://api.sandbox.ebay.com/identity/v1/oauth2/token",
        EndpointParams: url.Values{"redirect_uri": {"the RuName"}},
    }

Then I tried to make a request by creating an *http.Request:

req, err := http.NewRequest("GET", "https://api.sandbox.ebay.com/buy/browse/v1/item/v1|202117468662|0?fieldgroups=COMPACT", nil)
    if err != nil {
        log.Fatal(err)
    }
ctx := context.Background()
client := conf.Client(ctx)
res, err := client.Do(req)
if err != nil {
    log.Fatal(err)
}
defer res.Body.Close()

But then I get:

{
  "errors" : [ {
    "errorId" : 1003,
    "domain" : "OAuth",
    "category" : "REQUEST",
    "message" : "Token type in the Authorization header is invalid:Application",
    "longMessage" : "Token type in the Authorization header is invalid:Application"
  } ]
}

It turned out, that when making the request to the resource server Go's package sets the Authorization header as:

Authorization: Application Access Token token_string 

So, I tried to set the token type to Bearer manually by doing:

tok, err := conf.Token(ctx)
    if err != nil {
        log.Fatal(err)
    }

    client := conf.Client(ctx)
    req, err := http.NewRequest("GET", "https://api.sandbox.ebay.com/buy/browse/v1/item/v1|202117468662|0?fieldgroups=COMPACT", nil)
    if err != nil {
        log.Fatal(err)
    }
    req.Header.Set("Authorization", "Bearer " tok.AccessToken)
    res, err := client.Do(req)

But I continue getting the same error.

  • 写回答

1条回答 默认 最新

  • doujianguang5506 2018-03-14 19:49
    关注

    So, there is a problem (bug?) with the Ebay's implementation of the OAuth2.0 spec and I had to reimplement the TokenSource of the oauth2/clientcredentials package to set the token type to Bearer not Application Access Token.

    评论

报告相同问题?

悬赏问题

  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 请问这个是什么意思?
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样