Skip to content

Commit 820bb65

Browse files
committed
fix: microsoft login
1 parent 3549327 commit 820bb65

File tree

2 files changed

+11
-17
lines changed

2 files changed

+11
-17
lines changed

server/helpers/microsoft.js

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,12 @@ async function fetch(endpoint, accessToken) {
3030
}
3131
}
3232

33-
microsoft.getEmail = (microsoftUser) => {
34-
return microsoftUser.mail ? microsoftUser.mail : microsoftUser.userPrincipalName;
35-
}
36-
37-
microsoft.getProfilePicture = async (accessToken) => {
38-
return fetch('/v1.0/me/photo/$value', accessToken)
39-
}
40-
4133
microsoft.getMicrosoftUser = async (accessToken) => {
42-
return fetch('/v1.0/me', accessToken)
34+
return fetch('/oidc/userinfo', accessToken)
4335
}
4436

4537
microsoft.getUser = async (microsoftUser) => {
46-
const mail = microsoft.getEmail(microsoftUser)
38+
const mail = microsoftUser.email
4739
let user = await server.methods.user.get({ 'mail': mail }).catch((err) => {
4840
log.error({ err: err, microsoftUser }, '[Microsoft-Auth] Error getting user by Microsoft email')
4941
throw err
@@ -64,10 +56,12 @@ microsoft.getUser = async (microsoftUser) => {
6456
microsoft.createUser = async function (microsoftUser) {
6557
const user = {
6658
microsoft: {
67-
id: microsoftUser.id
59+
id: microsoftUser.sub
6860
},
69-
name: microsoftUser.displayName,
70-
mail: microsoft.getEmail(microsoftUser)
61+
name: microsoftUser.name,
62+
mail: microsoftUser.email,
63+
// Default image since Microsoft needs authentication to retrieve user's image
64+
img: 'https://static.sinfo.org/static/25-sinfo/speakers/hacky.png'
7165
}
7266

7367
log.debug('[Microsoft-Auth] Creating a new user', user)
@@ -81,4 +75,4 @@ microsoft.createUser = async function (microsoftUser) {
8175
return result.id
8276
}
8377

84-
module.exports = microsoft
78+
module.exports = microsoft

server/resources/auth.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,14 @@ async function microsoftAuth(accessToken) {
8787
if (res.createUser) {
8888
const userId = await microsoft.createUser(microsoftUser)
8989
return authenticate(userId, {
90-
name: microsoftUser.displayName,
91-
mail: microsoft.getEmail(microsoftUser)
90+
name: microsoftUser.name,
91+
mail: microsoftUser.email,
9292
})
9393
}
9494

9595
const changedAttributes = {
9696
microsoft: {
97-
id: microsoftUser.id
97+
id: microsoftUser.sub
9898
}
9999
}
100100

0 commit comments

Comments
 (0)