diff --git a/sasl/azure_event_hubs_entra/azure_event_hubs_entra.go b/sasl/azure_event_hubs_entra/azure_event_hubs_entra.go index f0cba28c..a3c0bae7 100755 --- a/sasl/azure_event_hubs_entra/azure_event_hubs_entra.go +++ b/sasl/azure_event_hubs_entra/azure_event_hubs_entra.go @@ -53,7 +53,8 @@ func (m *Mechanism) getEntraToken(ctx context.Context, saslMeta *sasl.Metadata) func buildTokenRequestOptions(saslMeta *sasl.Metadata) policy.TokenRequestOptions { tokenRequestOptions := policy.TokenRequestOptions{ - Scopes: []string{"https://" + saslMeta.Host}, + Scopes: []string{"https://" + saslMeta.Host + "/.default"}, + EnableCAE: false, } return tokenRequestOptions diff --git a/sasl/azure_event_hubs_entra/azure_event_hubs_entra_test.go b/sasl/azure_event_hubs_entra/azure_event_hubs_entra_test.go index 6ae576b4..723eab6c 100755 --- a/sasl/azure_event_hubs_entra/azure_event_hubs_entra_test.go +++ b/sasl/azure_event_hubs_entra/azure_event_hubs_entra_test.go @@ -3,6 +3,8 @@ package azure_event_hubs_entra import ( "context" "errors" + "fmt" + "strings" "testing" "github.com/Azure/azure-sdk-for-go/sdk/azcore" @@ -15,6 +17,24 @@ type MockTokenCredential struct { } func (c *MockTokenCredential) GetToken(ctx context.Context, options policy.TokenRequestOptions) (azcore.AccessToken, error) { + if len(options.Scopes) != 1 { + return azcore.AccessToken{}, fmt.Errorf("Scopes must contain 1 element! Contains %d elements.", len(options.Scopes)) + } + + scope := options.Scopes[0] + + if !strings.HasPrefix(scope, "https://") { + return azcore.AccessToken{}, fmt.Errorf("Scope must start with https, and it did not.") + } + + if !strings.HasSuffix(scope, "/.default") { + return azcore.AccessToken{}, fmt.Errorf("Scope must end with /.default, and it did not.") + } + + if options.EnableCAE { + return azcore.AccessToken{}, fmt.Errorf("CAE must be false. It was true.") + } + token, err := c.getTokenFunc() if err != nil {