{"action":"created","issue":{"url":"https://api.github.com/repos/Azure/azure-libraries-for-net/issues/195","repository_url":"https://api.github.com/repos/Azure/azure-libraries-for-net","labels_url":"https://api.github.com/repos/Azure/azure-libraries-for-net/issues/195/labels{/name}","comments_url":"https://api.github.com/repos/Azure/azure-libraries-for-net/issues/195/comments","events_url":"https://api.github.com/repos/Azure/azure-libraries-for-net/issues/195/events","html_url":"https://github.com/Azure/azure-libraries-for-net/pull/195","id":302056990,"number":195,"title":"Support custom\\external ServiceClientCredentials","user":{"login":"eric-winkler","id":2142978,"avatar_url":"https://avatars3.githubusercontent.com/u/2142978?v=4","gravatar_id":"","url":"https://api.github.com/users/eric-winkler","html_url":"https://github.com/eric-winkler","followers_url":"https://api.github.com/users/eric-winkler/followers","following_url":"https://api.github.com/users/eric-winkler/following{/other_user}","gists_url":"https://api.github.com/users/eric-winkler/gists{/gist_id}","starred_url":"https://api.github.com/users/eric-winkler/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eric-winkler/subscriptions","organizations_url":"https://api.github.com/users/eric-winkler/orgs","repos_url":"https://api.github.com/users/eric-winkler/repos","events_url":"https://api.github.com/users/eric-winkler/events{/privacy}","received_events_url":"https://api.github.com/users/eric-winkler/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2018-03-04T04:39:18Z","updated_at":"2018-04-19T19:27:24Z","closed_at":"2018-04-19T19:26:51Z","author_association":"CONTRIBUTOR","pull_request":{"url":"https://api.github.com/repos/Azure/azure-libraries-for-net/pulls/195","html_url":"https://github.com/Azure/azure-libraries-for-net/pull/195","diff_url":"https://github.com/Azure/azure-libraries-for-net/pull/195.diff","patch_url":"https://github.com/Azure/azure-libraries-for-net/pull/195.patch"},"body":"A number of the managers downcast the `RestClient`'s `Credentials` to `AzureCredentials` (eg https://github.com/Azure/azure-libraries-for-net/blob/master/src/ResourceManagement/Compute/ComputeManager.cs#L46).  Combined with the public facing side of the API accepting `ServiceClientCredentials` as input, we end up with an unfortunate violation of Liskov Substitution Principal that means code like this doesn't work;\r\n\r\n```\r\n// using Microsoft.Azure.Services.AppAuthentication(Prerelease)\r\nvar azureServiceTokenProvider = new AzureServiceTokenProvider();\r\nvar token = await azureServiceTokenProvider.GetAccessTokenAsync(\"https://management.core.windows.net/\");\r\nvar tenantId = azureServiceTokenProvider.PrincipalUsed.TenantId;\r\n\r\nvar client = RestClient\r\n\t.Configure()\r\n\t.WithEnvironment(AzureEnvironment.AzureGlobalCloud)\r\n\t.WithLogLevel(HttpLoggingDelegatingHandler.Level.Basic)\r\n\t.WithCredentials(new TokenCredentials(token))\r\n\t.Build();\r\n\r\n// throws \"Unable to cast object of type 'Microsoft.Rest.TokenCredentials' to type 'Microsoft.Azure.Management.ResourceManager.Fluent.Authentication.AzureCredentials'.\"\r\nvar azure = Azure\r\n\t.Authenticate(client, tenantId)\r\n\t.WithDefaultSubscription();\r\n```\r\n\r\nThis change moves us \"all in\" on the `AzureCredentials` usage on the `RestClient` and provides consumers a new (working) way to inject custom `ServiceClientCredentials` via a new constructor on `AzureCredentials`.\r\n\r\nThis is a breaking change from an API signature perspective, but as per the example above, I expect any code that was supplying ServiceClientCredentials would be broken anyway."},"comment":{"url":"https://api.github.com/repos/Azure/azure-libraries-for-net/issues/comments/382853340","html_url":"https://github.com/Azure/azure-libraries-for-net/pull/195#issuecomment-382853340","issue_url":"https://api.github.com/repos/Azure/azure-libraries-for-net/issues/195","id":382853340,"user":{"login":"hovsepm","id":7052173,"avatar_url":"https://avatars2.githubusercontent.com/u/7052173?v=4","gravatar_id":"","url":"https://api.github.com/users/hovsepm","html_url":"https://github.com/hovsepm","followers_url":"https://api.github.com/users/hovsepm/followers","following_url":"https://api.github.com/users/hovsepm/following{/other_user}","gists_url":"https://api.github.com/users/hovsepm/gists{/gist_id}","starred_url":"https://api.github.com/users/hovsepm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hovsepm/subscriptions","organizations_url":"https://api.github.com/users/hovsepm/orgs","repos_url":"https://api.github.com/users/hovsepm/repos","events_url":"https://api.github.com/users/hovsepm/events{/privacy}","received_events_url":"https://api.github.com/users/hovsepm/received_events","type":"User","site_admin":false},"created_at":"2018-04-19T19:27:24Z","updated_at":"2018-04-19T19:27:24Z","author_association":"CONTRIBUTOR","body":"Thanks for the contribution. This will be available from release v1.9"}}
{"actor":{"display_login":"hovsepm"}}