0

Get Current User

by
Published today

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

Script ms_teams Verified

The script

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

3
/**
4
 * Get Current User
5
 * Get the profile of the connected user: id, display name, email and user principal name. Requires User.Read (a connection default).
6
 */
7
export async function main(auth: RT.MsTeams) {
8
  const url = new URL(`https://graph.microsoft.com/v1.0/me`)
9

10
  const response = await fetch(url, {
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