Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion client/rest/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,26 @@ func ParseBody(accessToken string) (map[string]interface{}, error) {
}
}

// Entra ID issues tokens for the Azure Resource Manager under either of two
// registered identifier URIs; ARM accepts both, but AzureHound only compares
// against the canonical endpoint, so normalize the legacy form.
var audAliases = map[string]string{
"https://management.core.windows.net": "https://management.azure.com",
"https://management.core.usgovcloudapi.net": "https://management.usgovcloudapi.net",
"https://management.core.chinacloudapi.cn": "https://management.chinacloudapi.cn",
}

func ParseAud(accessToken string) (string, error) {
if body, err := ParseBody(accessToken); err != nil {
return "", err
} else if aud, ok := body["aud"].(string); !ok {
return "", fmt.Errorf("invalid 'aud' type: %T", body["aud"])
} else {
return strings.TrimSuffix(aud, "/"), nil
aud = strings.TrimSuffix(aud, "/")
if canonical, ok := audAliases[aud]; ok {
return canonical, nil
}
return aud, nil
}
}

Expand Down
Loading