MCPcopy Index your code
hub / github.com/coder/coder / main

Function main

scripts/oauth2/oauth2-test-server.go:41–172  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

39}
40
41func main() {
42 var serverOpts ServerOptions
43 flag.BoolVar(&serverOpts.KeepRunning, "keep-running", false, "Keep server running after successful authorization")
44 flag.Parse()
45
46 config := &Config{
47 ClientID: os.Getenv("CLIENT_ID"),
48 ClientSecret: os.Getenv("CLIENT_SECRET"),
49 CodeVerifier: os.Getenv("CODE_VERIFIER"),
50 State: os.Getenv("STATE"),
51 BaseURL: cmp.Or(os.Getenv("BASE_URL"), "http://localhost:3000"),
52 RedirectURI: "http://localhost:9876/callback",
53 }
54
55 if config.ClientID == "" || config.ClientSecret == "" {
56 log.Fatal("CLIENT_ID and CLIENT_SECRET must be set. Run: eval $(./setup-test-app.sh) first")
57 }
58
59 if config.CodeVerifier == "" || config.State == "" {
60 log.Fatal("CODE_VERIFIER and STATE must be set. Run test-manual-flow.sh to get these values")
61 }
62
63 var server *http.Server
64 ctx, cancel := context.WithCancel(context.Background())
65 defer cancel()
66
67 mux := http.NewServeMux()
68
69 mux.HandleFunc("/", func(w http.ResponseWriter, _ *http.Request) {
70 html := fmt.Sprintf(`
71<!DOCTYPE html>
72<html>
73<head>
74 <title>OAuth2 Test Server</title>
75 <style>
76 body { font-family: Arial, sans-serif; max-width: 800px; margin: 50px auto; padding: 20px; }
77 .status { padding: 20px; margin: 20px 0; border-radius: 5px; }
78 .waiting { background: #fff3cd; color: #856404; }
79 .success { background: #d4edda; color: #155724; }
80 .error { background: #f8d7da; color: #721c24; }
81 pre { background: #f5f5f5; padding: 15px; overflow-x: auto; }
82 a { color: #0066cc; }
83 </style>
84</head>
85<body>
86 <h1>OAuth2 Test Server</h1>
87 <div class="status waiting">
88 <h2>Waiting for OAuth2 callback...</h2>
89 <p>Please authorize the application in your browser.</p>
90 <p>Listening on: <code>%s</code></p>
91 </div>
92</body>
93</html>`, config.RedirectURI)
94 w.Header().Set("Content-Type", "text/html")
95 _, _ = fmt.Fprint(w, html)
96 })
97
98 mux.HandleFunc("/callback", func(w http.ResponseWriter, r *http.Request) {

Callers

nothing calls this directly

Calls 11

ShutdownMethod · 0.95
showErrorFunction · 0.85
exchangeTokenFunction · 0.85
showSuccessFunction · 0.85
FatalMethod · 0.80
ParseMethod · 0.65
SetMethod · 0.65
GetMethod · 0.65
HeaderMethod · 0.45
FatalfMethod · 0.45
DoneMethod · 0.45

Tested by

no test coverage detected