Skip to content

Commit 424bd04

Browse files
authored
fix(providers): refactor Azure AD provider to support v4 (#2818)
1 parent a177bbb commit 424bd04

File tree

2 files changed

+23
-12
lines changed

2 files changed

+23
-12
lines changed

app/components/header.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,7 @@ export default function Header() {
3939
{session && (
4040
<>
4141
{session.user.image && (
42-
<span
43-
style={{ backgroundImage: `url(${session.user.image})` }}
44-
className={styles.avatar}
45-
/>
42+
<img src={session.user.image} className={styles.avatar} />
4643
)}
4744
<span className={styles.signedInText}>
4845
<small>Signed in as</small>

src/providers/azure-ad.js

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,29 @@ export default function AzureAD(options) {
66
id: "azure-ad",
77
name: "Azure Active Directory",
88
type: "oauth",
9-
authorization: `https://login.microsoftonline.com/${tenant}/oauth2/v2.0/authorize?response_mode=query`,
10-
token: `https://login.microsoftonline.com/${tenant}/oauth2/v2.0/token`,
11-
userinfo: "https://graph.microsoft.com/v1.0/me/",
12-
profile(profile) {
9+
wellKnown: `https://login.microsoftonline.com/${tenant}/v2.0/.well-known/openid-configuration`,
10+
authorization: {
11+
params: {
12+
scope: "User.Read",
13+
},
14+
},
15+
async profile(profile, tokens) {
16+
// https://docs.microsoft.com/en-us/graph/api/profilephoto-get?view=graph-rest-1.0#examples
17+
const profilePicture = await fetch(
18+
"https://graph.microsoft.com/v1.0/me/photo/$value",
19+
{
20+
headers: {
21+
Authorization: `Bearer ${tokens.access_token}`,
22+
},
23+
}
24+
)
25+
const pictureBuffer = await profilePicture.arrayBuffer()
26+
const pictureBase64 = Buffer.from(pictureBuffer).toString("base64")
1327
return {
14-
id: profile.id,
15-
name: profile.displayName,
16-
email: profile.userPrincipalName,
17-
image: null,
28+
id: profile.sub,
29+
name: profile.name,
30+
email: profile.email,
31+
image: `data:image/jpeg;base64, ${pictureBase64}`,
1832
}
1933
},
2034
options,

0 commit comments

Comments
 (0)