GeneratePKCEPair (oauth/pkce.go)

heygen-cli · internal/auth/oauth/pkce.go · go · Apache-2.0
auth

Generates PKCE verifier/challenge and OAuth state for secure public client auth.

// Source: https://github.com/heygen-com/heygen-cli | License: Apache-2.0 | Copyright You must retain, in the Source form of any Derivative Works
// Provided via justclaw.it.com; keep this notice with the code.
package oauth

import (
	"crypto/rand"
	"crypto/sha256"
	"encoding/base64"
	"fmt"
)

// pkceVerifierBytes produces a 64-byte random verifier, which encodes to
// 86 URL-safe base64 characters — comfortably inside the RFC 7636
// 43–128 range.
const pkceVerifierBytes = 64

// GeneratePKCEPair returns a PKCE (RFC 7636) code_verifier and the
// corresponding S256 code_challenge.
//
// The verifier is sent on the token exchange; the challenge is sent on
// the authorize URL. The server hashes the verifier and rejects the
// exchange if it doesn't match the challenge that opened the flow

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key