Skip to content

Instantly share code, notes, and snippets.

@yshuman1
Created December 23, 2018 04:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yshuman1/2b496e0fe698a5a0df087c60f4583677 to your computer and use it in GitHub Desktop.
Save yshuman1/2b496e0fe698a5a0df087c60f4583677 to your computer and use it in GitHub Desktop.
broken callback func
sqCallback := func(w http.ResponseWriter, r *http.Request) {
r.ParseForm()
state := r.FormValue("state")
cookie, err := r.Cookie("oauth_state")
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
} else if cookie == nil || cookie.Value != state {
http.Error(w, "invalid state provided", http.StatusBadRequest)
return
}
cookie.Value = ""
cookie.Expires = time.Now()
http.SetCookie(w, cookie)
code := r.FormValue("code")
token, err := sqOAuth.Exchange(context.Background(), code)
if err != nil {
fmt.Println("breaking when trying to get token")
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
fmt.Fprintf(w, "%+v", token)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment