forked from navikt/helsesjekk-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ms-graph.ts
70 lines (60 loc) · 2.01 KB
/
ms-graph.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// import { headers } from 'next/headers'
// import { logger } from '@navikt/next-logger'
import { isLocal } from '../utils/env'
import { fakeMembersOfResponse } from './fake-members-of-response'
// import { getUserToken } from './authentication'
/* eslint-disable @typescript-eslint/no-unused-vars */
export async function getMembersOf(): Promise<
MsGraphGroupsResponse | { error: string; status?: number; statusText?: string }
> {
if (isLocal) {
return fakeMembersOfResponse
}
// TODO: integrate with entra ID
return fakeMembersOfResponse
/* const token = getUserToken(headers())
const tokenSet = await requestOboToken(token, 'https://graph.microsoft.com/.default')
if (!tokenSet.ok) {
logger.error(new Error(`Unable to exchange OBO token: ${tokenSet.error.message}`, { cause: tokenSet.error }))
return { error: 'Du har ikke tilgang til å se dine grupper.' }
}
const response = await fetch('https://graph.microsoft.com/v1.0/me/memberOf?$top=999', {
headers: {
Authorization: `Bearer ${tokenSet.token}`,
},
})
if (!response.ok) {
return {
error: 'Feil fra Microsoft, prøv igjen senere.',
status: response.status,
statusText: response.statusText,
}
}
return response.json() */
}
export type MsGraphGroup = {
id: string
createdDateTime: string
description?: string
displayName: string | null
groupTypes: string[]
mail?: string
mailEnabled: boolean
mailNickname: string
onPremisesDomainName?: string
onPremisesLastSyncDateTime?: string
onPremisesNetBiosName?: string
onPremisesSamAccountName?: string
onPremisesSecurityIdentifier?: string
onPremisesSyncEnabled?: boolean
proxyAddresses: string[]
renewedDateTime: string
securityEnabled: boolean
securityIdentifier: string
visibility?: string
}
type MsGraphGroupsResponse = {
'@odata.context': string
'@odata.nextLink'?: string
value: MsGraphGroup[]
}