Skip to content

Instantly share code, notes, and snippets.

@tomcam
Created May 7, 2019 00:14
Show Gist options
  • Save tomcam/c64e9588fea02088a3a5073b9cf1c32c to your computer and use it in GitHub Desktop.
Save tomcam/c64e9588fea02088a3a5073b9cf1c32c to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Auth Accepted</title>
</head>
<body>
<h1>User signed in and Granted Authorization</h1>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Auth Declined</title>
</head>
<body>
<h1>User refused authorization</h1>
</body>
</html>
package main
import (
"fmt"
"log"
"net/http"
"os"
)
func main() {
// Must run as sudo.
if os.Getenv("SUDO_USER") == "" {
fmt.Println("\nUsage: sudo " + os.Args[0] + " 2>>stderror.log\n")
log.Fatal("")
}
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
http.ServeFile(w, r, "./index.html")
// First step: consent request.
// See "Setting the target endpoint" at:
// https://developer.ebay.com/api-docs/static/oauth-consent-request.html
url :=
"https://signin.sandbox.ebay.com/authorize?" +
"&client_id=" + "eSnipeIn-Rapidfir-SBX-70902ebf9-78dade17" +
"&redirect_uri=" + "eSnipe__Inc.-eSnipeIn-Rapidf-nmfmqvfgs" +
"&response_type=code" +
"&scope=https%3A%2F%2Fapi.ebay.com%2Foauth%2Fapi_scope%2Fbuy.offer.auction" +
"&state=DEADBEEF" +
"&prompt=login"
w.Header().Set("Content-Type", "application/x-www-form-urlencoded")
// This GET shown under "The consent request" here:
// https://developer.ebay.com/api-docs/static/oauth-consent-request.html
client := &http.Client{}
req, err := http.NewRequest("GET", url, nil)
if err != nil {
log.Fatal(err)
}
resp, err := client.Do(req)
// &redirect_uri pointed to /auth-accepted.html
// and this GET request causes us to redirect there.
if err != nil {
log.Fatal(err)
}
defer resp.Body.Close()
})
http.HandleFunc("./auth-accepted.html", func(w http.ResponseWriter, r *http.Request) {
http.ServeFile(w, r, "./auth-accepted.html")
// URL in the browser title bar shows the parameter
// &code with the correct payload, which is a long string
// containing the auth code.
fmt.Fprintf(os.Stdout, r.FormValue("code"))
})
http.HandleFunc("./auth-declined.html", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "DECLINED")
})
log.Fatal(http.ListenAndServe(":80", nil))
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Privacy</title>
</head>
<body>
<h1>eSnipe Privacy Policy</h1>
<p>Your data is encrypted at rest.</p>
<p><script>var now = new Date(); document.write(now)</script></p>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment