generated from mattermost/mattermost-plugin-starter-template
-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathendpoints.go
More file actions
47 lines (40 loc) · 1.27 KB
/
endpoints.go
File metadata and controls
47 lines (40 loc) · 1.27 KB
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
package msgraph
import (
"golang.org/x/oauth2"
)
var tenantLoginEndpoint string
var tenantMSGraphEndpoint string
// Returns the Entra ID endpoint for the given tenant and tenant type.
func EntraIDEndpoint(tenant string, tenantType string) oauth2.Endpoint {
if tenant == "" {
tenant = "common"
}
switch tenantType {
case "gcch", "usgov":
tenantLoginEndpoint = "https://login.microsoftonline.us/"
case "china":
tenantLoginEndpoint = "https://login.chinacloudapi.cn/"
default:
tenantLoginEndpoint = "https://login.microsoftonline.com/"
}
return oauth2.Endpoint{
AuthURL: tenantLoginEndpoint + tenant + "/oauth2/v2.0/authorize",
TokenURL: tenantLoginEndpoint + tenant + "/oauth2/v2.0/token",
DeviceAuthURL: tenantLoginEndpoint + tenant + "/oauth2/v2.0/devicecode",
}
}
// nolint:revive
// Returns the Microsoft Graph endpoint for the given tenant type.
func MSGraphEndpoint(tenantType string) string {
switch tenantType {
case "gcch":
tenantMSGraphEndpoint = "https://graph.microsoft.us"
case "usgov":
tenantMSGraphEndpoint = "https://dod-graph.microsoft.us"
case "china":
tenantMSGraphEndpoint = "https://microsoftgraph.chinacloudapi.cn"
default:
tenantMSGraphEndpoint = "https://graph.microsoft.com"
}
return tenantMSGraphEndpoint + "/v1.0"
}