AuthCodeURL generates the authorization URL with PKCE and returns session data.
(ctx context.Context, state string)
| 120 | |
| 121 | // AuthCodeURL generates the authorization URL with PKCE and returns session data. |
| 122 | func (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 | |
| 147 | func generateNonce() (string, error) { |
| 148 | b := make([]byte, 32) |
no test coverage detected