Looking at Twitter example I tried to implement it for my project. Below you can see 2 functions:
2013/11/19 05:19:39 httpExecute: HTTP response is not 200/OK as expected. Actual response:
Response Status: '401 Unauthorized'
Response Code: 401
Response Body: Invalid request token
Requst Headers: [key: Authorization, val: OAuth oauth_consumer_key="eGhxxEwyi1AOgQhtQNi1g",oauth_nonce="6812501655763588603",oauth_signature="5%2Ffqo84h2tfujYk3q6x13dpdaY8%3D",oauth_signature_method="HMAC-SHA1",oauth_timestamp="1384831178",oauth_token="2SzuHTzXp93rj4TJJXy0sHYs2Wg7l9pTpNE3oLs8",oauth_verifier="",oauth_version="1.0"][key: Content-Length, val: 0]
exit status 1
func AskTwitterVerificationCode(w http.ResponseWriter, r *http.Request) {
c := oauth.NewConsumer(
config.TwitterConsumerKey,
config.TwitterConsumerSecret,
oauth.ServiceProvider{
RequestTokenUrl: "http://api.twitter.com/oauth/request_token",
AuthorizeTokenUrl: "https://api.twitter.com/oauth/authorize",
AccessTokenUrl: "https://api.twitter.com/oauth/access_token",
},
)
if config.Debug {
c.Debug(true)
}
var requestUrl, tokenUrl string
if config.Debug {
tokenUrl = "http://myapp.com:"+strconv.Itoa(config.Port)+"/auth/twitter/callback"
} else {
tokenUrl = "http://myapp.com/auth/twitter/callback"
}
var err error
_, requestUrl, err = c.GetRequestTokenAndUrl(tokenUrl)
if err != nil {
log.Fatal(err)
}
http.Redirect(w, r, requestUrl, http.StatusMovedPermanently)
}
func GetTwitterToken(w http.ResponseWriter, r *http.Request) {
c := oauth.NewConsumer(
config.TwitterConsumerKey,
config.TwitterConsumerSecret,
oauth.ServiceProvider{
RequestTokenUrl: "http://api.twitter.com/oauth/request_token",
AuthorizeTokenUrl: "https://api.twitter.com/oauth/authorize",
AccessTokenUrl: "https://api.twitter.com/oauth/access_token",
},
)
if config.Debug {
c.Debug(true)
}
var tokenUrl string
var requestToken *oauth.RequestToken
if config.Debug {
tokenUrl = "http://myapp.com:"+strconv.Itoa(config.Port)+"/auth/twitter/callback"
} else {
tokenUrl = "http://myapp.com/auth/twitter/callback"
}
var err error
requestToken, _, err = c.GetRequestTokenAndUrl(tokenUrl)
if err != nil {
log.Fatal(err)
}
values := r.URL.Query()
verificationCode := values.Get("oauth_verifier")
log.Println(verificationCode)
accessToken, err := c.AuthorizeToken(requestToken, verificationCode)
if err != nil {
log.Fatal(err)
}
fmt.Fprintf(w, accessToken.Token, " and ", accessToken.Secret)
}