Skip to content

Commit d54f949

Browse files
committed
feat: add interactive OAuth setup wizard
Add user-friendly OAuth configuration helper script that provides: Features: - Interactive menu with 4 options - Step-by-step setup instructions for Google, GitHub, LinkedIn - Color-coded output for better readability - Error handling and validation - Automatic .env backup before changes - Test credentials option for UI testing - Detection of existing OAuth configuration Usage: ./scripts/setup-oauth.sh Options: 1. View detailed setup instructions (12 min total) 2. Manually edit .env file 3. Add test credentials (OAuth buttons visible but non-functional) 4. Exit Benefits: - Reduces OAuth setup friction for new developers - Clear time estimates per provider - Safe testing with placeholder credentials - Complements existing docs/oauth-setup-guide.md Related to PR #25 authentication features
1 parent 3436b85 commit d54f949

File tree

1 file changed

+247
-0
lines changed

1 file changed

+247
-0
lines changed

scripts/setup-oauth.sh

Lines changed: 247 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,247 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
# Colors for better readability
6+
RED='\033[0;31m'
7+
GREEN='\033[0;32m'
8+
YELLOW='\033[1;33m'
9+
BLUE='\033[0;34m'
10+
PURPLE='\033[0;35m'
11+
CYAN='\033[0;36m'
12+
NC='\033[0m' # No Color
13+
BOLD='\033[1m'
14+
15+
ENV_FILE="packages/server/.env"
16+
17+
# Header
18+
clear
19+
echo -e "${PURPLE}${BOLD}"
20+
echo "╔══════════════════════════════════════════════════════════════╗"
21+
echo "║ ║"
22+
echo "║ 🔐 GraphDone OAuth Setup Helper 🔐 ║"
23+
echo "║ ║"
24+
echo "╚══════════════════════════════════════════════════════════════╝"
25+
echo -e "${NC}"
26+
echo ""
27+
echo -e "${CYAN}This wizard will help you set up OAuth social login for:${NC}"
28+
echo -e " ${GREEN}${NC} Google"
29+
echo -e " ${GREEN}${NC} GitHub"
30+
echo -e " ${GREEN}${NC} LinkedIn"
31+
echo ""
32+
echo -e "${YELLOW}⏱️ Total time: ~12 minutes (Google: 5min, GitHub: 2min, LinkedIn: 5min)${NC}"
33+
echo ""
34+
35+
# Check if .env file exists
36+
if [ ! -f "$ENV_FILE" ]; then
37+
echo -e "${RED}❌ Error: $ENV_FILE not found!${NC}"
38+
echo -e "${YELLOW}💡 Run this script from the GraphDone project root directory.${NC}"
39+
exit 1
40+
fi
41+
42+
# Check current OAuth status
43+
echo -e "${CYAN}Checking current OAuth configuration...${NC}"
44+
if grep -q "GOOGLE_CLIENT_ID=" "$ENV_FILE" && ! grep -q "GOOGLE_CLIENT_ID=$" "$ENV_FILE" && ! grep -q 'GOOGLE_CLIENT_ID=""' "$ENV_FILE"; then
45+
echo -e "${GREEN}✓ OAuth credentials already configured${NC}"
46+
echo ""
47+
read -p "Do you want to update existing OAuth credentials? (y/n) " -n 1 -r
48+
echo
49+
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
50+
echo -e "${CYAN}👋 Exiting. Your existing OAuth configuration is unchanged.${NC}"
51+
exit 0
52+
fi
53+
else
54+
echo -e "${YELLOW}⚠️ OAuth not configured yet${NC}"
55+
fi
56+
echo ""
57+
58+
# Main menu
59+
echo -e "${BOLD}What would you like to do?${NC}"
60+
echo ""
61+
echo " 1) 📖 View step-by-step setup instructions"
62+
echo " 2) ✏️ Manually edit .env file"
63+
echo " 3) 🧪 Add test credentials (OAuth buttons visible but non-functional)"
64+
echo " 4) ❌ Exit"
65+
echo ""
66+
read -p "Choose an option (1-4): " choice
67+
68+
case $choice in
69+
1)
70+
# Detailed instructions
71+
clear
72+
echo -e "${PURPLE}${BOLD}📖 OAuth Setup Instructions${NC}"
73+
echo "══════════════════════════════════════════════════════════════"
74+
echo ""
75+
76+
echo -e "${GREEN}${BOLD}1️⃣ Google OAuth (5 minutes)${NC}"
77+
echo -e "${CYAN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
78+
echo " a) Visit: https://console.cloud.google.com/"
79+
echo " b) Create a new project or select existing"
80+
echo " c) Click ☰ → 'APIs & Services' → 'Credentials'"
81+
echo " d) Click '+ CREATE CREDENTIALS' → 'OAuth client ID'"
82+
echo " e) If prompted, configure OAuth consent screen:"
83+
echo " • User Type: External"
84+
echo " • App name: GraphDone Local"
85+
echo " • User support email: your email"
86+
echo " f) Application type: 'Web application'"
87+
echo " g) Name: GraphDone Local Dev"
88+
echo " h) Authorized redirect URIs → Add:"
89+
echo -e " ${YELLOW}https://localhost:4128/auth/google/callback${NC}"
90+
echo " i) Click CREATE and copy Client ID & Secret"
91+
echo ""
92+
93+
echo -e "${GREEN}${BOLD}2️⃣ GitHub OAuth (2 minutes)${NC}"
94+
echo -e "${CYAN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
95+
echo " a) Visit: https://github.com/settings/developers"
96+
echo " b) Click 'OAuth Apps' → 'New OAuth App'"
97+
echo " c) Fill in:"
98+
echo " • Application name: GraphDone Local"
99+
echo " • Homepage URL: http://localhost:3127"
100+
echo " • Authorization callback URL:"
101+
echo -e " ${YELLOW}https://localhost:4128/auth/github/callback${NC}"
102+
echo " d) Click 'Register application'"
103+
echo " e) Copy Client ID"
104+
echo " f) Click 'Generate a new client secret' and copy it"
105+
echo ""
106+
107+
echo -e "${GREEN}${BOLD}3️⃣ LinkedIn OAuth (5 minutes)${NC}"
108+
echo -e "${CYAN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
109+
echo " a) Visit: https://www.linkedin.com/developers/apps"
110+
echo " b) Click 'Create app'"
111+
echo " c) Fill in:"
112+
echo " • App name: GraphDone Local"
113+
echo " • LinkedIn Page: Select or create"
114+
echo " • Check 'I have read and agree to these terms'"
115+
echo " d) Click 'Create app'"
116+
echo " e) Go to 'Auth' tab"
117+
echo " f) Under 'Authorized redirect URLs' → Add redirect URL:"
118+
echo -e " ${YELLOW}https://localhost:4128/auth/linkedin/callback${NC}"
119+
echo " g) Click 'Update'"
120+
echo " h) Go to 'Products' tab → Find 'Sign In with LinkedIn'"
121+
echo " i) Click 'Request access' (usually auto-approved)"
122+
echo " j) Return to 'Auth' tab and copy Client ID & Secret"
123+
echo ""
124+
125+
echo -e "${CYAN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
126+
echo ""
127+
echo -e "${BOLD}📝 Add these to ${YELLOW}packages/server/.env${NC}${BOLD}:${NC}"
128+
echo ""
129+
cat << 'ENVEXAMPLE'
130+
# OAuth - Google
131+
GOOGLE_CLIENT_ID=your-google-client-id.apps.googleusercontent.com
132+
GOOGLE_CLIENT_SECRET=your-google-client-secret
133+
GOOGLE_CALLBACK_URL=https://localhost:4128/auth/google/callback
134+
135+
# OAuth - GitHub
136+
GITHUB_CLIENT_ID=your-github-client-id
137+
GITHUB_CLIENT_SECRET=your-github-client-secret
138+
GITHUB_CALLBACK_URL=https://localhost:4128/auth/github/callback
139+
140+
# OAuth - LinkedIn
141+
LINKEDIN_CLIENT_ID=your-linkedin-client-id
142+
LINKEDIN_CLIENT_SECRET=your-linkedin-client-secret
143+
LINKEDIN_CALLBACK_URL=https://localhost:4128/auth/linkedin/callback
144+
ENVEXAMPLE
145+
echo ""
146+
echo -e "${YELLOW}⚡ Quick tip: You can start with just Google OAuth to test!${NC}"
147+
echo ""
148+
echo -e "${GREEN}🔄 After adding credentials, restart: ${BOLD}./start${NC}"
149+
echo ""
150+
151+
read -p "Would you like to edit the .env file now? (y/n) " -n 1 -r
152+
echo
153+
if [[ $REPLY =~ ^[Yy]$ ]]; then
154+
echo -e "${CYAN}Opening $ENV_FILE...${NC}"
155+
sleep 1
156+
${EDITOR:-nano} "$ENV_FILE"
157+
echo ""
158+
echo -e "${GREEN}✅ File saved! Restart GraphDone with: ${BOLD}./start${NC}"
159+
fi
160+
;;
161+
162+
2)
163+
# Direct edit
164+
echo ""
165+
echo -e "${CYAN}Opening $ENV_FILE for editing...${NC}"
166+
echo -e "${YELLOW}💡 Refer to docs/oauth-setup-guide.md for detailed setup steps${NC}"
167+
sleep 2
168+
${EDITOR:-nano} "$ENV_FILE"
169+
echo ""
170+
echo -e "${GREEN}✅ File saved! Restart GraphDone with: ${BOLD}./start${NC}"
171+
;;
172+
173+
3)
174+
# Test credentials
175+
echo ""
176+
echo -e "${YELLOW}${BOLD}⚠️ Warning: Test Credentials${NC}"
177+
echo ""
178+
echo "This will add placeholder OAuth credentials that:"
179+
echo -e " ${GREEN}${NC} Make OAuth buttons visible in the UI"
180+
echo -e " ${RED}${NC} Won't actually authenticate users"
181+
echo ""
182+
echo "Use this only for:"
183+
echo " • UI testing and development"
184+
echo " • Screenshots and demos"
185+
echo " • Verifying button placement"
186+
echo ""
187+
read -p "Continue? (y/n) " -n 1 -r
188+
echo
189+
190+
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
191+
echo -e "${CYAN}Cancelled. No changes made.${NC}"
192+
exit 0
193+
fi
194+
195+
# Backup existing .env
196+
cp "$ENV_FILE" "$ENV_FILE.backup.$(date +%Y%m%d_%H%M%S)"
197+
echo -e "${GREEN}✓ Created backup of .env${NC}"
198+
199+
# Add test credentials if not present
200+
if ! grep -q "GOOGLE_CLIENT_ID=" "$ENV_FILE"; then
201+
cat >> "$ENV_FILE" << 'EOF'
202+
203+
# OAuth Test Credentials (UI testing only - won't authenticate)
204+
GOOGLE_CLIENT_ID=test-google-id.apps.googleusercontent.com
205+
GOOGLE_CLIENT_SECRET=test-google-secret
206+
GOOGLE_CALLBACK_URL=https://localhost:4128/auth/google/callback
207+
208+
GITHUB_CLIENT_ID=test-github-id
209+
GITHUB_CLIENT_SECRET=test-github-secret
210+
GITHUB_CALLBACK_URL=https://localhost:4128/auth/github/callback
211+
212+
LINKEDIN_CLIENT_ID=test-linkedin-id
213+
LINKEDIN_CLIENT_SECRET=test-linkedin-secret
214+
LINKEDIN_CALLBACK_URL=https://localhost:4128/auth/linkedin/callback
215+
EOF
216+
echo -e "${GREEN}✓ Test credentials added to $ENV_FILE${NC}"
217+
else
218+
echo -e "${YELLOW}ℹ️ OAuth credentials already present in $ENV_FILE${NC}"
219+
fi
220+
221+
echo ""
222+
echo -e "${CYAN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
223+
echo -e "${BOLD}Next steps:${NC}"
224+
echo -e " 1. Restart GraphDone: ${GREEN}./start${NC}"
225+
echo -e " 2. Visit: ${CYAN}https://localhost:3128${NC}"
226+
echo -e " 3. OAuth buttons should now be visible"
227+
echo -e " 4. Replace with real credentials when ready"
228+
echo -e "${CYAN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
229+
echo ""
230+
;;
231+
232+
4)
233+
echo -e "${CYAN}👋 Exiting. No changes made.${NC}"
234+
exit 0
235+
;;
236+
237+
*)
238+
echo -e "${RED}❌ Invalid option. Exiting.${NC}"
239+
exit 1
240+
;;
241+
esac
242+
243+
echo ""
244+
echo -e "${GREEN}${BOLD}✅ Setup complete!${NC}"
245+
echo ""
246+
echo -e "${CYAN}📚 For more details, see: ${YELLOW}docs/oauth-setup-guide.md${NC}"
247+
echo ""

0 commit comments

Comments
 (0)