@@ -11,6 +11,17 @@ import (
11
11
"github.com/google/go-github/v64/github"
12
12
)
13
13
14
+ // getGithubMiddleware sets up authentication middleware for GitHub OAuth.
15
+ // If clientID and secret are empty, the middleware does nothing.
16
+ //
17
+ // Parameters:
18
+ // - clientID: The OAuth client ID issued by GitHub when registering the application.
19
+ // - secret: The OAuth client secret used to securely authenticate API requests.
20
+ // - cooldown: A cooldown duration to prevent several claims from the same user.
21
+ //
22
+ // GitHub OAuth applications require a client ID and secret to authenticate users securely.
23
+ // These credentials are obtained when registering an application on GitHub at:
24
+ // https://docs.github.com/en/apps/oauth-apps/building-oauth-apps/authenticating-to-the-rest-api-with-an-oauth-app#registering-your-app
14
25
func getGithubMiddleware (clientID , secret string , cooldown time.Duration ) func (next http.Handler ) http.Handler {
15
26
coolDownLimiter := NewCooldownLimiter (cooldown )
16
27
return func (next http.Handler ) http.Handler {
@@ -24,6 +35,13 @@ func getGithubMiddleware(clientID, secret string, cooldown time.Duration) func(n
24
35
return
25
36
}
26
37
38
+ // Extracts the authorization code returned by the GitHub OAuth flow.
39
+ //
40
+ // When a user successfully authenticates via GitHub OAuth, GitHub redirects them
41
+ // to the registered callback URL with a `code` query parameter. This code is then
42
+ // exchanged for an access token.
43
+ //
44
+ // Reference: https://docs.github.com/en/apps/oauth-apps/building-oauth-apps/authorizing-oauth-apps#2-users-are-redirected-back-to-your-site-by-github
27
45
code := r .URL .Query ().Get ("code" )
28
46
if code == "" {
29
47
http .Error (w , "missing code" , http .StatusBadRequest )
0 commit comments