Skip to content

Commit 7ff028d

Browse files
committed
feat: enhance OAuth2UserInfoLocal type and update user info retrieval
1 parent 4b1f439 commit 7ff028d

1 file changed

Lines changed: 20 additions & 4 deletions

File tree

index.ts

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
import type { OAuth2Adapter } from "adminforth";
22

3+
type OAuth2UserInfoLocal = {
4+
email: string;
5+
provider?: string;
6+
subject?: string;
7+
phone?: string;
8+
meta?: Record<string, any>;
9+
fullName?: string;
10+
profilePictureUrl?: string | null;
11+
externalUserId?: string | number | null;
12+
};
313
export default class AdminForthAdapterFacebookOauth2 implements OAuth2Adapter {
414
private clientID: string;
515
private clientSecret: string;
@@ -22,7 +32,7 @@ export default class AdminForthAdapterFacebookOauth2 implements OAuth2Adapter {
2232
return `https://www.facebook.com/v22.0/dialog/oauth?${params.toString()}`;
2333
}
2434

25-
async getTokenFromCode(code: string, redirect_uri: string): Promise<{ email: string, fullName: string, profilePictureUrl?: string }> {
35+
async getTokenFromCode(code: string, redirect_uri: string): Promise<OAuth2UserInfoLocal> {
2636
// Exchange code for token
2737
const tokenResponse = await fetch('https://graph.facebook.com/v22.0/oauth/access_token', {
2838
method: 'POST',
@@ -43,7 +53,7 @@ export default class AdminForthAdapterFacebookOauth2 implements OAuth2Adapter {
4353
}
4454

4555
// Get user info using access token
46-
const userResponse = await fetch(`https://graph.facebook.com/me?fields=id,email&access_token=${tokenData.access_token}`, {
56+
const userResponse = await fetch(`https://graph.facebook.com/me?fields=id,email,name,picture&access_token=${tokenData.access_token}`, {
4757
method: 'GET',
4858
headers: { 'Content-Type': 'application/json' },
4959
});
@@ -55,13 +65,19 @@ export default class AdminForthAdapterFacebookOauth2 implements OAuth2Adapter {
5565
}
5666

5767
return {
68+
provider: this.constructor.name,
69+
subject: userData.id,
5870
email: userData.email,
5971
fullName: userData.name,
6072
profilePictureUrl: userData.picture?.data?.url,
6173
};
6274
}
6375

64-
getIcon(): string {
76+
getName(): string {
77+
return 'Facebook';
78+
}
79+
80+
getIcon(): string {
6581
return `<svg xmlns="http://www.w3.org/2000/svg" xmlns:svg="http://www.w3.org/2000/svg" version="1.1" id="svg9" viewBox="0 0 666.66668 666.66717">
6682
<defs id="defs13">
6783
<clipPath clipPathUnits="userSpaceOnUse" id="clipPath25">
@@ -83,4 +99,4 @@ getIcon(): string {
8399
<script xmlns=""/></svg>`;
84100
}
85101

86-
}
102+
}

0 commit comments

Comments
 (0)