Hi
For my below code I am getting the error as given below please help:
Error:
getBody: httpExecute: HTTP response is not 200/OK as expected. Actual response:
Response Status: '400 Bad Request'
Response Code: 400
Response Body: {"errors":[{"code":215,"message":"Bad Authentication data."}]}
Request Headers: [key: Authorization, val: OAuth oauth_callback="http%3A%2F%2Flocalhost%3A8080%2Fauth%2Ftwitter%2Fcallback",oauth_consumer_key="",oauth_nonce="3365417980319125505",oauth_signature="LLKgHISKim8lcgKYU2fsCreLLlU%3D",oauth_signature_method="HMAC-SHA1",oauth_timestamp="1462389865",oauth_version="1.0"]
The Program:
// webgoauth1 project main.go
package main
import (
"encoding/json"
"fmt"
"html/template"
"log"
"net/http"
"os"
"github.com/gorilla/sessions"
"github.com/gorilla/pat"
"github.com/markbates/goth"
"github.com/markbates/goth/gothic"
// "github.com/markbates/goth/providers/facebook"
"github.com/markbates/goth/providers/twitter"
)
type Configuration struct{
TwitterKey string
TwitterSecret string
FacebookKey string
FacebookSecret string
}
var config Configuration
func init() {
gothic.Store = sessions.NewFilesystemStore(os.TempDir(), []byte("goth-example"))
file,_ := os.Open("config.json")
decoder := json.NewDecoder(file)
config := Configuration{}
err := decoder.Decode(&config)
if err != nil {
log.Fatal(err)
}
fmt.Println(config.TwitterKey)
fmt.Println(config.TwitterSecret)
}
func callbackAuthHandler(res http.ResponseWriter, req *http.Request) {
user, err := gothic.CompleteUserAuth(res,req)
if err != nil {
fmt.Fprintln(res,err)
return
}
t , _ := template.New("user").Parse(userTemplate)
t.Execute(res,user)
}
func indexHandler(res http.ResponseWriter,req *http.Request){
t,_ := template.New("index").Parse(indexTemplate)
t.Execute(res,nil)
}
func main() {
goth.UseProviders(
twitter.New(config.TwitterKey, config.TwitterSecret, "http://localhost:8080/auth/twitter/callback"),
// facebook.New(config.FacebookKey, config.FacebookSecret, "http://localhost:8080/auth/facebook/callback"),
)
r := pat.New()
r.Get("/auth/{provider}/callback", callbackAuthHandler)
r.Get("/auth/{provider}", gothic.BeginAuthHandler)
r.Get("/",indexHandler)
server := &http.Server{
Addr: ":8080",
Handler: r,
}
log.Println("Listening")
server.ListenAndServe()
}
var indexTemplate = `
Log in with Twitter
Log in with Facebook
var userTemplate =
Name {{.Name}}
Email {{.Email}}
NickName {{.NickName}}
Location {{.Location}}
AvatharURL {{.AvatharURL}}
Description {{.Description}}
UserID {{.UserID}}
AccessToken {{.AccessToken}}
`