diff options
| author | mo khan <mo@mokhan.ca> | 2022-04-06 14:13:00 -0600 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2022-04-06 14:13:00 -0600 |
| commit | 1c6107462a31f7dd776cc6e4b4e7d427f4fddf5b (patch) | |
| tree | 4122da9c103910c35eab602271d4de75fe250fa3 | |
| parent | b30c73fda4849ede583d8cbf7bd56799c4f3cb55 (diff) | |
response to authorization code request
| -rwxr-xr-x | src/oidc/bin/authz_code | 6 | ||||
| -rw-r--r-- | src/oidc/go.mod | 3 | ||||
| -rw-r--r-- | src/oidc/main.go | 48 |
3 files changed, 57 insertions, 0 deletions
diff --git a/src/oidc/bin/authz_code b/src/oidc/bin/authz_code new file mode 100755 index 0000000..fa96133 --- /dev/null +++ b/src/oidc/bin/authz_code @@ -0,0 +1,6 @@ +#!/bin/sh + +set -e +cd "$(dirname "$0")/.." + +curl -v -s "http://localhost:8282/authorize?response_type=code&scope=openid&client_id=f00d&state=potatoe&redirect_uri=https://client.example.org/callback" diff --git a/src/oidc/go.mod b/src/oidc/go.mod new file mode 100644 index 0000000..6d19d06 --- /dev/null +++ b/src/oidc/go.mod @@ -0,0 +1,3 @@ +module github.com/hashicorp/xlgmokha/src/oidc + +go 1.18 diff --git a/src/oidc/main.go b/src/oidc/main.go new file mode 100644 index 0000000..fd80c0d --- /dev/null +++ b/src/oidc/main.go @@ -0,0 +1,48 @@ +package main + +import ( + "fmt" + "log" + "net/http" +) + +func main() { + log.Println("Starting server, listening on port 8282.") + + server := &http.Server{ + Addr: ":8282", + Handler: http.HandlerFunc(handler), + ReadTimeout: 0, + WriteTimeout: 0, + IdleTimeout: 0, + } + + log.Fatal(server.ListenAndServe()) +} + +type AuthorizationRequest struct { + ResponseType string + Scope string + ClientId string + State string + RedirectUri string +} + +func handler(w http.ResponseWriter, r *http.Request) { + if r.URL.Path == "/" && r.Method == "GET" { + w.WriteHeader(http.StatusOK) + fmt.Fprintf(w, "Hello, world!\n") + } else if r.URL.Path == "/authorize" && r.Method == "GET" { + ar := &AuthorizationRequest{ + ResponseType: r.FormValue("response_type"), + Scope: r.FormValue("scope"), + ClientId: r.FormValue("client_id"), + State: r.FormValue("state"), + RedirectUri: r.FormValue("redirect_uri"), + } + http.Redirect(w, r, fmt.Sprintf("%s?code=example&state=%s", ar.RedirectUri, ar.State), 302) + } else { + log.Printf("method: %s path: %s error: unsupported request\n", r.Method, r.URL.Path) + w.WriteHeader(http.StatusNotFound) + } +} |
