forked from coder/coder
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate-pkce.sh
More file actions
executable file
·26 lines (20 loc) · 849 Bytes
/
Copy pathgenerate-pkce.sh
File metadata and controls
executable file
·26 lines (20 loc) · 849 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#!/bin/bash
# Generate PKCE code verifier and challenge for OAuth2 flow
# Usage: ./generate-pkce.sh
# Generate code verifier (43-128 characters, URL-safe)
CODE_VERIFIER=$(openssl rand -base64 32 | tr -d "=+/" | cut -c -43)
# Generate code challenge (S256 method)
CODE_CHALLENGE=$(echo -n "$CODE_VERIFIER" | openssl dgst -sha256 -binary | base64 | tr -d "=" | tr '+/' '-_')
echo "Code Verifier: $CODE_VERIFIER"
echo "Code Challenge: $CODE_CHALLENGE"
# Export as environment variables for use in other scripts
export CODE_VERIFIER
export CODE_CHALLENGE
echo ""
echo "Environment variables set:"
echo " CODE_VERIFIER=\"$CODE_VERIFIER\""
echo " CODE_CHALLENGE=\"$CODE_CHALLENGE\""
echo ""
echo "Usage in curl:"
echo " curl \"...&code_challenge=$CODE_CHALLENGE&code_challenge_method=S256\""
echo " curl -d \"code_verifier=$CODE_VERIFIER\" ..."