Azure-Samples / media-services-v3-dotnet

The projects in this repository show how to implement different Azure Media Services scenarios using the v3 version.
MIT License
58 stars 52 forks source link

Unauthorized error when running tests #60

Closed kadlard closed 1 year ago

kadlard commented 2 years ago

Please provide us with the following information:

This issue is for a: (mark with an x)

- [ ] bug report -> please search issues before submitting
- [ ] feature request
- [ ] documentation issue or request
- [ ] regression (a behavior that used to work and stopped in a new release)

Minimal steps to reproduce

I have been following the readme. I just finished successfully running the deploy.ps1 file. I have added the access policy to allow my account access to the keyvault. I have update the keyvault name in the E2ETest.cs as well as a sample video. When the test runs, it gets an unauthorized exception at

            var client = mediaServiceInstanceFactory.GetMediaServiceInstance(config.Value.AccountName, Mock.Of<ILogger>());
            client.LongRunningOperationRetryTimeout = 2;

            await MediaServicesHelper.EnsureTransformExists(
                client,
                config.Value.ResourceGroup,
                config.Value.AccountName,
                transformName,
                new BuiltInStandardEncoderPreset(EncoderNamedPreset.AdaptiveStreaming)).ConfigureAwait(false);

After a bit more digging, its the request to create or update against the storage account that seems to fail

Document   | Name | Value | Type -- | -- | -- | --   | CallInfo | "PUT transforms/TestTransform" | string ▶ | EventTime | {2022-05-10 2:51:01 AM +00:00} | System.DateTimeOffset   | HttpStatus | Unauthorized | System.Net.HttpStatusCode   | Id | "___________" | string   | MediaServiceAccountName | "________amswestus" | string

Any log messages given by the failure

SubmitTestRequests  Source: E2ETests.cs line 112  Duration: 8.2 sec

Message:  Test method HighAvailability.Tests.E2ETests.SubmitTestRequests threw exception: Microsoft.Azure.Management.Media.Models.ApiErrorException: Operation returned an invalid status code 'Unauthorized'

Stack Trace:  TransformsOperations.CreateOrUpdateWithHttpMessagesAsync(String resourceGroupName, String accountName, String transformName, IList1 outputs, String description, Dictionary2 customHeaders, CancellationToken cancellationToken) TransformsOperationsExtensions.CreateOrUpdateAsync(ITransformsOperations operations, String resourceGroupName, String accountName, String transformName, IList`1 outputs, String description, CancellationToken cancellationToken) MediaServicesHelper.EnsureTransformExists(IAzureMediaServicesClient client, String resourceGroupName, String accountName, String transformName, Preset preset) line 44 E2ETests.SubmitTestRequests() line 124 ThreadOperations.ExecuteWithAbortSafety(Action action)

Expected/desired behavior

OS and Version?

Windows 7, 8 or 10. Linux (which distribution). macOS (Yosemite? El Capitan? Sierra?)

Versions

Mention any other details that might be useful


Thanks! We'll be in touch soon.

kadlard commented 2 years ago

Issue seems to be authenticating against the azure media services. not sure if maybe something changed in azure, but authentication isnt working

kadlard commented 2 years ago

https://docs.microsoft.com/en-us/azure/media-services/latest/configure-connect-dotnet-howto

needed to update code to create AAD service principal and use that to authenticate

IngridAtMicrosoft commented 2 years ago

Thank you @kadlard! Your input will be reviewed shortly.

johndeu commented 1 year ago

Recommendation with the latest SDK is to use Managed Identity and the DefaultCredential object. Closing this for now with the new updated samples, it should be clearer and more consistent across all of the .NET 7 version of the SDKs.