0

Identify an admin

by
Published Dec 20, 2024

You can view the currently authorised admin along with the embedded app object (a "workspace" in legacy terminology). > 🚧 Single Sign On > > If you are building a custom "Log in with Intercom" flow for your site, and you call the `/me` endpoint to identify the logged-in user, you should not accept any sign-ins from users with unverified email addresses as it poses a potential impersonation security risk.

Script intercom Verified

The script

Submitted by hugo697 Bun
Verified 536 days ago
1
//native
2
type Intercom = {
3
	apiVersion: string
4
	token: string
5
}
6
/**
7
 * Identify an admin
8
 * 
9
You can view the currently authorised admin along with the embedded app object (a "workspace" in legacy terminology).
10

11
> 🚧 Single Sign On
12
>
13
> If you are building a custom "Log in with Intercom" flow for your site, and you call the `/me` endpoint to identify the logged-in user, you should not accept any sign-ins from users with unverified email addresses as it poses a potential impersonation security risk.
14

15
 */
16
export async function main(auth: Intercom) {
17
	const url = new URL(`https://api.intercom.io/me`)
18

19
	const response = await fetch(url, {
20
		method: 'GET',
21
		headers: {
22
			'Intercom-Version': auth.apiVersion,
23
			Authorization: 'Bearer ' + auth.token
24
		},
25
		body: undefined
26
	})
27
	if (!response.ok) {
28
		const text = await response.text()
29
		throw new Error(`${response.status} ${text}`)
30
	}
31
	return await response.json()
32
}
33