Created
December 23, 2018 04:34
-
-
Save yshuman1/2b496e0fe698a5a0df087c60f4583677 to your computer and use it in GitHub Desktop.
broken callback func
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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