1import React from "react";
2import { generateCodeVerifier, generateCodeChallenge } from "./utils/pkce";
3
4export function SocialLoginButtons() {
5 const handleOAuthLogin = async (provider: "google" | "github") => {
6 const verifier = generateCodeVerifier();
7 const challenge = await generateCodeChallenge(verifier);
8
9 // Persist verifier temporarily in sessionStorage for callback verification
10 sessionStorage.setItem("pkce_verifier", verifier);
11
12 const endpoints = {
13 google: "https://accounts.google.com/o/oauth2/v2/auth",
14 github: "https://github.com/login/oauth/authorize",
15 };
16
17 const clientIds = {
18 google: "ENTERPRISE_GOOGLE_CLIENT_ID.apps.googleusercontent.com",
19 github: "ENTERPRISE_GITHUB_CLIENT_ID",
20 };
21
22 const params = new URLSearchParams({
23 client_id: clientIds[provider],
24 redirect_uri: `${window.location.origin}/auth/callback`,
25 response_type: "code",
26 scope: provider === "google" ? "openid profile email" : "read:user user:email",
27 code_challenge: challenge,
28 code_challenge_method: "S256",
29 state: crypto.randomUUID(), // CSRF prevention token
30 });
31
32 // Redirect user to Identity Provider login page
33 window.location.href = `${endpoints[provider]}?${params.toString()}`;
34 };
35
36 return (
37 <div className="space-y-3 max-w-sm p-6 bg-slate-900 border border-slate-800 rounded-xl">
38 <h2 className="text-white font-bold text-lg mb-4">Enterprise Single Sign-On</h2>
39
40 <button
41 onClick={() => handleOAuthLogin("google")}
42 className="w-full py-2.5 px-4 bg-white text-slate-900 font-semibold rounded-lg flex items-center justify-center gap-2 hover:bg-slate-100 transition"
43 >
44 Continue with Google Workspace
45 </button>
46
47 <button
48 onClick={() => handleOAuthLogin("github")}
49 className="w-full py-2.5 px-4 bg-slate-800 text-white font-semibold rounded-lg flex items-center justify-center gap-2 hover:bg-slate-700 transition"
50 >
51 Continue with GitHub Enterprise
52 </button>
53 </div>
54 );
55}