@@ -13,12 +13,51 @@ import (
1313)
1414
1515const (
16- loginUrl = "https://login.microsoftonline.com/"
1716 grantType = "client_credentials"
18- scope = "https://manage.office.com/.default"
1917 endPointLogin = "/oauth2/v2.0/token"
2018)
2119
20+ type CloudEnvironment string
21+
22+ const (
23+ CloudCommercial CloudEnvironment = "Commercial"
24+ CloudGCC CloudEnvironment = "GCC"
25+ CloudGCCHigh CloudEnvironment = "GCCHigh"
26+ CloudDoD CloudEnvironment = "DoD"
27+ )
28+
29+ type CloudConfig struct {
30+ LoginAuthority string
31+ Scope string
32+ }
33+
34+ func getCloudConfig (env CloudEnvironment ) CloudConfig {
35+ configs := map [CloudEnvironment ]CloudConfig {
36+ CloudCommercial : {
37+ LoginAuthority : "https://login.microsoftonline.com/" ,
38+ Scope : "https://manage.office.com/.default" ,
39+ },
40+ CloudGCC : {
41+ LoginAuthority : "https://login.microsoftonline.com/" ,
42+ Scope : "https://manage-gcc.office.com/.default" ,
43+ },
44+ CloudGCCHigh : {
45+ LoginAuthority : "https://login.microsoftonline.us/" ,
46+ Scope : "https://manage.office365.us/.default" ,
47+ },
48+ CloudDoD : {
49+ LoginAuthority : "https://login.microsoftonline.us/" ,
50+ Scope : "https://manage.protection.apps.mil/.default" ,
51+ },
52+ }
53+
54+ cloudConfig , exists := configs [env ]
55+ if ! exists {
56+ return configs [CloudCommercial ]
57+ }
58+ return cloudConfig
59+ }
60+
2261type MicrosoftLoginResponse struct {
2362 TokenType string `json:"token_type,omitempty"`
2463 Expires int `json:"expires_in,omitempty"`
@@ -30,6 +69,7 @@ type MicrosoftLoginResponse struct {
3069
3170func ValidateO365Config (config * config.ModuleGroup ) error {
3271 var clientId , clientSecret , tenantId string
72+ var cloudEnvironment CloudEnvironment = CloudCommercial
3373
3474 if config == nil {
3575 return fmt .Errorf ("O365 configuration is nil" )
@@ -43,6 +83,10 @@ func ValidateO365Config(config *config.ModuleGroup) error {
4383 clientSecret = cnf .ConfValue
4484 case "office365_tenant_id" :
4585 tenantId = cnf .ConfValue
86+ case "office365_cloud_environment" :
87+ if cnf .ConfValue != "" {
88+ cloudEnvironment = CloudEnvironment (cnf .ConfValue )
89+ }
4690 }
4791 }
4892
@@ -56,14 +100,16 @@ func ValidateO365Config(config *config.ModuleGroup) error {
56100 return fmt .Errorf ("Tenant ID is required in O365 configuration" )
57101 }
58102
103+ cloudConfig := getCloudConfig (cloudEnvironment )
104+
59105 // Validate credentials by attempting to get an access token
60- requestUrl := fmt .Sprintf ("%s%s%s" , loginUrl , tenantId , endPointLogin )
106+ requestUrl := fmt .Sprintf ("%s%s%s" , cloudConfig . LoginAuthority , tenantId , endPointLogin )
61107
62108 data := url.Values {}
63109 data .Set ("grant_type" , grantType )
64110 data .Set ("client_id" , clientId )
65111 data .Set ("client_secret" , clientSecret )
66- data .Set ("scope" , scope )
112+ data .Set ("scope" , cloudConfig . Scope )
67113
68114 client := & http.Client {
69115 Timeout : 10 * time .Second ,
0 commit comments