Skip to content

Commit f06515c

Browse files
Fixed the AzureTenantId in oauth.go (#210)
AzureTenantId was hardcoded as a constant which was linked to ".staging.azuredatabricks.net". Therefore, if the host URL was for example from ".azuredatabricks.net", it failed to detect ClientId. I replaced the const value with a map to find the AzureTenantId based on the DSN host. --------- Signed-off-by: Erfan Mahmoodnejad <[email protected]> Co-authored-by: Erfan Mahmoodnejad <[email protected]>
1 parent aeb5e5d commit f06515c

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

auth/oauth/oauth.go

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,13 @@ import (
1010
"golang.org/x/oauth2"
1111
)
1212

13-
const (
14-
azureTenantId = "4a67d088-db5c-48f1-9ff2-0aace800ae68"
15-
)
13+
var azureTenants = map[string]string{
14+
".dev.azuredatabricks.net": "62a912ac-b58e-4c1d-89ea-b2dbfc7358fc",
15+
".staging.azuredatabricks.net": "4a67d088-db5c-48f1-9ff2-0aace800ae68",
16+
".azuredatabricks.net": "2ff814a6-3304-4ab8-85cb-cd0e6f879c1d",
17+
".databricks.azure.us": "2ff814a6-3304-4ab8-85cb-cd0e6f879c1d",
18+
".databricks.azure.cn": "2ff814a6-3304-4ab8-85cb-cd0e6f879c1d",
19+
}
1620

1721
func GetEndpoint(ctx context.Context, hostName string) (oauth2.Endpoint, error) {
1822
if ctx == nil {
@@ -52,7 +56,7 @@ func GetScopes(hostName string, scopes []string) []string {
5256

5357
cloudType := InferCloudFromHost(hostName)
5458
if cloudType == Azure {
55-
userImpersonationScope := fmt.Sprintf("%s/user_impersonation", azureTenantId)
59+
userImpersonationScope := fmt.Sprintf("%s/user_impersonation", azureTenants[GetAzureDnsZone(hostName)])
5660
if !HasScope(scopes, userImpersonationScope) {
5761
scopes = append(scopes, userImpersonationScope)
5862
}
@@ -133,3 +137,12 @@ func InferCloudFromHost(hostname string) CloudType {
133137
}
134138
return Unknown
135139
}
140+
141+
func GetAzureDnsZone(hostname string) string {
142+
for _, d := range databricksAzureDomains {
143+
if strings.Contains(hostname, d) {
144+
return d
145+
}
146+
}
147+
return ""
148+
}

0 commit comments

Comments
 (0)