Last active
February 7, 2024 23:12
-
-
Save cheikhsimsol/e86609d8f7bc90a191b74d3591b5bf68 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
mux.HandleFunc("GET /consume", func(w http.ResponseWriter, r *http.Request) { | |
ctx := context.Background() | |
code := r.FormValue("code") | |
state := r.FormValue("state") | |
if state != "state" { | |
http.Error(w, "Error, mismatched state", http.StatusBadRequest) | |
return | |
} | |
tok, err := conf.Exchange(ctx, code) | |
if err != nil { | |
http.Error(w, "Error exchanging token", http.StatusInternalServerError) | |
return | |
} | |
client := conf.Client(ctx, tok) | |
res, err := client.Get("https://oauth.wiremockapi.cloud/userinfo") | |
if err != nil { | |
http.Error(w, "Error fetching data", http.StatusInternalServerError) | |
return | |
} | |
defer res.Body.Close() | |
// Set the content type based on the response header | |
w.Header().Set("Content-Type", res.Header.Get("Content-Type")) | |
// Copy the response body to the client's response writer | |
_, err = io.Copy(w, res.Body) | |
if err != nil { | |
http.Error(w, "Error streaming data", http.StatusInternalServerError) | |
return | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment