Skip to content
This repository was archived by the owner on May 2, 2024. It is now read-only.

Commit b33d65e

Browse files
author
Elliott Barrere
committed
Add azure_environment option to config
to allow switching between Commercial and GCC-H Azure environments
1 parent 622bd4f commit b33d65e

2 files changed

Lines changed: 10 additions & 3 deletions

File tree

internal/aad/aad.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ import (
1515
)
1616

1717
const (
18-
endpoint = "https://login.microsoftonline.com"
19-
2018
invalidCredCode = 50126
2119
requiresMFACode = 50076
2220
noSuchUserCode = 50034
@@ -25,6 +23,8 @@ const (
2523
)
2624

2725
var (
26+
endpoint = "https://login.microsoftonline.com"
27+
2828
// ErrNoNetwork is returned in case of no network available.
2929
ErrNoNetwork = errors.New("NO NETWORK")
3030
// ErrDeny is returned in case of denial returned by AAD.
@@ -46,6 +46,9 @@ type AAD struct {
4646

4747
// Authenticate tries to authenticate username against AAD.
4848
func (auth AAD) Authenticate(ctx context.Context, cfg config.AAD, username, password string) error {
49+
if cfg.AzureEnvironment == "GCC-H" {
50+
endpoint = "https://login.microsoftonline.us"
51+
}
4952
authority := fmt.Sprintf("%s/%s", endpoint, cfg.TenantID)
5053
logger.Debug(ctx, "Connecting to %q, with clientID %q for user %q", authority, cfg.AppID, username)
5154

@@ -104,7 +107,7 @@ func (auth AAD) Authenticate(ctx context.Context, cfg config.AAD, username, pass
104107

105108
logger.Debug(ctx, "For more information about the error code(s), see:")
106109
for _, errcode := range addErrWithCodes.ErrorCodes {
107-
logger.Debug(ctx, "- Error code %d: https://login.microsoftonline.com/error?code=%d", errcode, errcode)
110+
logger.Debug(ctx, "- Error code %d: %s/error?code=%d", errcode, endpoint, errcode)
108111
}
109112

110113
return ErrDeny

internal/config/config.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ const (
2323
type AAD struct {
2424
TenantID string `ini:"tenant_id"`
2525
AppID string `ini:"app_id"`
26+
AzureEnvironment string `ini:"azure_environment"`
2627
OfflineCredentialsExpiration *int `ini:"offline_credentials_expiration"`
2728
HomeDirPattern string `ini:"homedir"`
2829
Shell string `ini:"shell"`
@@ -93,6 +94,9 @@ func Load(ctx context.Context, p, domain string, opts ...Option) (config AAD, er
9394
if config.AppID == "" {
9495
return AAD{}, fmt.Errorf("missing required 'app_id' entry in configuration file")
9596
}
97+
if config.AzureEnvironment == "" {
98+
config.AzureEnvironment = "Commercial"
99+
}
96100

97101
return config, nil
98102
}

0 commit comments

Comments
 (0)