0

I'm trying to implement oauth-workflow for GitHub in golang and using https://github.com/franela/goreq to perform http(s) requests.

There is a section in which GitHub returns a code and you have to make a POST request to https://github.com/login/oauth/access_token with code, client_id and client_secret.

package main

import "fmt"
import "github.com/franela/goreq"

type param struct {
  code string
  client_id string
  client_secret string
}

func main() {
  params := param {code: "XX", client_id:"XX", client_secret: "XX"}
  req := goreq.Request{
    Method : "POST",
    Uri : "https://github.com/login/oauth/access_token",
    Body : params,
  }
  req.AddHeader("Content-Type", "application/json")
  req.AddHeader("Accept", "application/json")
  res, _ := req.Do()
  fmt.Println(res.Body.ToString())
}

It is giving 404 with {"error":"Not Found"} message always. While using Python, I'm getting the correct results with the same input data.

2 Answers 2

3

You are generating empty JSON objects. Your struct fields should start in capitals for the JSON encoder to be able to encode them.

type goodparam struct {
    Code         string `json:"code"`
    ClientId     string `json:"client_id"`
    ClientSecret string `json:"client_secret"`
}

See this in action.

Sign up to request clarification or add additional context in comments.

Comments

0

You should double check your 'client_secret' and 'client_id' (must be right because you get the code) if it is correct, apparently Github returns HTTP status code 404 if it is wrong.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.