@openinc/parse-server-opendash 3.29.6 → 3.29.8

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.
@@ -34,6 +34,34 @@ function getKey(header, callback) {
34
34
  callback(null, key.getPublicKey());
35
35
  });
36
36
  }
37
+ /**
38
+ * Fetches the email address of the user from Microsoft Graph API.
39
+ * @param accessToken The access token to authenticate the request.
40
+ * @returns The email address of the user.
41
+ */
42
+ async function getUserMail(accessToken) {
43
+ const response = await fetch("https://graph.microsoft.com/v1.0/me", {
44
+ method: "GET",
45
+ headers: {
46
+ Authorization: `Bearer ${accessToken}`,
47
+ Accept: "application/json",
48
+ },
49
+ });
50
+ if (!response.ok) {
51
+ console.error(`Failed to fetch user info: ${response.status} ${response.statusText}`);
52
+ return null;
53
+ }
54
+ const data = (await response.json());
55
+ if (data.mail) {
56
+ return data.mail;
57
+ }
58
+ else if (data.userPrincipalName) {
59
+ return data.userPrincipalName;
60
+ }
61
+ else {
62
+ return null;
63
+ }
64
+ }
37
65
  async function init(name) {
38
66
  Parse.Cloud.define(name, async (request) => {
39
67
  const token = request.params.token;
@@ -73,6 +101,7 @@ async function init(name) {
73
101
  resolve(decoded);
74
102
  });
75
103
  });
104
+ const usermail = await getUserMail(request.params.accessToken);
76
105
  const defaultTenant = await new Parse.Query(types_1.Tenant)
77
106
  .ascending("createdAt")
78
107
  .first({ useMasterKey: true });
@@ -83,11 +112,11 @@ async function init(name) {
83
112
  let oldUser = (await new Parse.Query(Parse.User)
84
113
  .equalTo("username", verifiedPayload.oid)
85
114
  .first({ useMasterKey: true }));
86
- console.log("Payload: ", JSON.stringify(verifiedPayload));
115
+ console.log("Payload: ", JSON.stringify(verifiedPayload), "account:", JSON.stringify(account));
87
116
  if (!user && !oldUser) {
88
117
  user = new Parse.User();
89
118
  user.set("username", account.username);
90
- user.set("email", account.mail ?? account.username);
119
+ user.set("email", usermail ?? account.username);
91
120
  user.set("password", (0, crypto_1.randomBytes)(16).toString("hex"));
92
121
  user.set("microsoftId", verifiedPayload.oid);
93
122
  user.set("name", verifiedPayload.name || verifiedPayload.preferred_username);
@@ -100,7 +129,7 @@ async function init(name) {
100
129
  user = oldUser;
101
130
  user.set("microsoftId", verifiedPayload.oid);
102
131
  user.set("username", account.username);
103
- user.set("email", account.mail ?? account.username);
132
+ user.set("email", usermail ?? account.username);
104
133
  user = await user.save(null, { useMasterKey: true });
105
134
  }
106
135
  const sessionToken = "r:" + (0, crypto_1.randomBytes)(16).toString("hex");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openinc/parse-server-opendash",
3
- "version": "3.29.6",
3
+ "version": "3.29.8",
4
4
  "description": "Parse Server Cloud Code for open.INC Stack.",
5
5
  "packageManager": "pnpm@10.20.0",
6
6
  "keywords": [