signinwith 1.0.10 → 1.0.12
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 +18 -16
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -25,25 +25,27 @@ export const verifySigninApple = async (config, verificationData) => {
|
|
|
25
25
|
return result.email ? { success: true, email: result.email } : { success: false, error: 'Email not available from Apple' };
|
|
26
26
|
};
|
|
27
27
|
export const verifySigninDiscord = async (config, verificationData) => {
|
|
28
|
+
const params = new URLSearchParams();
|
|
29
|
+
params.append('grant_type', 'authorization_code');
|
|
30
|
+
params.append('code', verificationData.code);
|
|
31
|
+
params.append('redirect_uri', config.redirectUri);
|
|
32
|
+
|
|
28
33
|
const tokenResponse = await fetch('https://discord.com/api/v10/oauth2/token', {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
});
|
|
42
|
-
const token = await tokenResponse.json();
|
|
43
|
-
verificationData.accessToken = token.access_token;
|
|
34
|
+
method: 'POST',
|
|
35
|
+
body: params,
|
|
36
|
+
headers: {
|
|
37
|
+
'Content-Type': 'application/x-www-form-urlencoded',
|
|
38
|
+
'Authorization': `Basic ${btoa(`${config.clientId}:${config.clientSecret}`)}`
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
const token = await tokenResponse.json();
|
|
42
|
+
if (!tokenResponse.ok) {
|
|
43
|
+
return { success: false, error: token.error_description || 'Failed to exchange Discord code for token' };
|
|
44
|
+
}
|
|
45
|
+
const accessToken = token.access_token;
|
|
44
46
|
const res = await fetch('https://discord.com/api/v10/users/@me', {
|
|
45
47
|
headers: {
|
|
46
|
-
authorization: `Bearer ${
|
|
48
|
+
authorization: `Bearer ${accessToken}`,
|
|
47
49
|
},
|
|
48
50
|
});
|
|
49
51
|
const profile = await res.json();
|
package/package.json
CHANGED