0

Get Current User

by
Published today

Get the profile of the connected account (id, display name, mail, user principal name). Requires User.Read (a connection default).

Script ms_sharepoint Verified

The script

Submitted by hugo989 Typescript (fetch-only)
Verified 4 hours ago
1
//native
2

3
const graph = "https://graph.microsoft.com/v1.0"
4

5
/**
6
 * Get Current User
7
 * Get the profile of the connected account (id, display name, mail, user principal name). Requires User.Read (a connection default).
8
 */
9
export async function main(auth: RT.MsSharepoint) {
10
  const response = await fetch(`${graph}/me`, {
11
    headers: {
12
      Authorization: `Bearer ${auth.token}`,
13
      Accept: "application/json",
14
    },
15
  })
16

17
  if (!response.ok) {
18
    throw new Error(`${response.status} ${await response.text()}`)
19
  }
20

21
  return await response.json()
22
}
23