signinwith 1.2.0 → 1.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +32 -2
- package/package.json +1 -1
- package/react.jsx +1 -0
- package/readme.md +3 -0
package/index.js
CHANGED
|
@@ -1,7 +1,37 @@
|
|
|
1
1
|
export const verifySigninGoogle = async (config, verificationData) => {
|
|
2
|
-
|
|
2
|
+
if (!verificationData?.code) return { success: false, error: 'Missing Google authorization code' };
|
|
3
|
+
if (!config?.clientId || !config?.clientSecret) return { success: false, error: 'Google clientId and clientSecret are required' };
|
|
4
|
+
|
|
5
|
+
const params = new URLSearchParams();
|
|
6
|
+
params.append('code', verificationData.code);
|
|
7
|
+
params.append('client_id', config.clientId);
|
|
8
|
+
params.append('client_secret', config.clientSecret);
|
|
9
|
+
params.append('redirect_uri', new URL(config.redirectUri || 'https://example.com').origin);
|
|
10
|
+
params.append('grant_type', 'authorization_code');
|
|
11
|
+
|
|
12
|
+
const tokenResponse = await fetch('https://oauth2.googleapis.com/token', {
|
|
13
|
+
method: 'POST',
|
|
14
|
+
headers: {
|
|
15
|
+
'Content-Type': 'application/x-www-form-urlencoded',
|
|
16
|
+
},
|
|
17
|
+
body: params,
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
const token = await tokenResponse.json();
|
|
21
|
+
if (!tokenResponse.ok || token.error) {
|
|
22
|
+
return { success: false, error: token.error_description || 'Failed to exchange Google code for token' };
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const res = await fetch(`https://www.googleapis.com/oauth2/v3/tokeninfo?id_token=${token.id_token}`);
|
|
3
26
|
const payload = await res.json();
|
|
4
|
-
|
|
27
|
+
|
|
28
|
+
if (payload.error) {
|
|
29
|
+
return { success: false, error: payload.error_description || 'Invalid Google token' };
|
|
30
|
+
}
|
|
31
|
+
if (payload.aud !== config.clientId) {
|
|
32
|
+
return { success: false, error: 'Mismatch in clientID and "aud" value.' };
|
|
33
|
+
}
|
|
34
|
+
|
|
5
35
|
return payload.email ? { success: true, email: payload.email } : { success: false, error: 'Email not found' };
|
|
6
36
|
};
|
|
7
37
|
|
package/package.json
CHANGED
package/react.jsx
CHANGED
|
@@ -84,6 +84,7 @@ export function SignInWithGoogle({ service, onSignin, onError }) {
|
|
|
84
84
|
client_id: service.clientId,
|
|
85
85
|
scope: "openid email profile",
|
|
86
86
|
ux_mode: "popup",
|
|
87
|
+
redirect_uri: service.redirectUri,
|
|
87
88
|
callback: (res) => {
|
|
88
89
|
// res.code is the authorization code (send to backend)
|
|
89
90
|
if (!res?.code) return onError?.("No auth code received from Google.");
|
package/readme.md
CHANGED
|
@@ -31,6 +31,7 @@ function App() {
|
|
|
31
31
|
const services = {
|
|
32
32
|
google: {
|
|
33
33
|
clientId: 'YOUR_GOOGLE_CLIENT_ID.apps.googleusercontent.com',
|
|
34
|
+
redirectUri: 'https://yourdomain.com/redirect-oauth.html', // Need to match your OAuth origin settings
|
|
34
35
|
},
|
|
35
36
|
facebook: {
|
|
36
37
|
appId: 'YOUR_FACEBOOK_APP_ID',
|
|
@@ -105,6 +106,8 @@ app.use(express.json());
|
|
|
105
106
|
const servicesConfig = {
|
|
106
107
|
google: {
|
|
107
108
|
clientId: process.env.GOOGLE_CLIENT_ID,
|
|
109
|
+
clientSecret: process.env.GOOGLE_CLIENT_SECRET,
|
|
110
|
+
redirectUri: 'https://yourdomain.com/redirect-oauth.html', // Need to match your OAuth origin settings
|
|
108
111
|
},
|
|
109
112
|
facebook: {
|
|
110
113
|
// Facebook verification only needs the access token from the frontend
|