MCPcopy Create free account
hub / github.com/PatchMon/PatchMon / AuthCodeURL

Method AuthCodeURL

server-source-code/internal/auth/oidc/client.go:122–145  ·  view source on GitHub ↗

AuthCodeURL generates the authorization URL with PKCE and returns session data.

(ctx context.Context, state string)

Source from the content-addressed store, hash-verified

120
121// AuthCodeURL generates the authorization URL with PKCE and returns session data.
122func (c *Client) AuthCodeURL(ctx context.Context, state string) (authURL string, session *SessionData, err error) {
123 if err := c.connect(ctx); err != nil {
124 return "", nil, err
125 }
126 verifier := oauth2.GenerateVerifier()
127 nonce, err := generateNonce()
128 if err != nil {
129 return "", nil, fmt.Errorf("oidc: generate nonce: %w", err)
130 }
131
132 opts := []oauth2.AuthCodeOption{
133 oauth2.S256ChallengeOption(verifier),
134 oauth2.SetAuthURLParam("nonce", nonce),
135 }
136
137 authURL = c.oauth2.AuthCodeURL(state, opts...)
138
139 session = &SessionData{
140 State: state,
141 CodeVerifier: verifier,
142 Nonce: nonce,
143 }
144 return authURL, session, nil
145}
146
147func generateNonce() (string, error) {
148 b := make([]byte, 32)

Callers 1

LoginMethod · 0.80

Calls 2

connectMethod · 0.95
generateNonceFunction · 0.85

Tested by

no test coverage detected