Skip to content

Use ADAL 3 and Microsoft.Rest.ClientRuntime.Azure.Authentication #1314

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Nov 18, 2015
Merged
Show file tree
Hide file tree
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 src/CLU.sln
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.23107.0
VisualStudioVersion = 14.0.24711.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{8531411A-0137-4E27-9C5E-49E07C245048}"
ProjectSection(SolutionItems) = preProject
Expand Down Expand Up @@ -53,6 +53,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sync", "ServiceManagement\C
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VhdManagement", "ServiceManagement\Compute\VhdManagement\VhdManagement.csproj", "{80496B7B-068A-4A1E-B0BB-4B1FFF3FA616}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Common.Authentication", "Common\Authentication\Common.Authentication\Common.Authentication.csproj", "{B95C489C-8CB7-4DCF-8D5F-B9AEBDBBAF89}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Common.Authentication.Tests", "Common\Authentication\Common.Authentication.Tests\Common.Authentication.Tests.csproj", "{C2CF99A2-D35E-4AED-AFB9-C26960AF1D0D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -143,6 +147,14 @@ Global
{80496B7B-068A-4A1E-B0BB-4B1FFF3FA616}.Debug|Any CPU.Build.0 = Debug|Any CPU
{80496B7B-068A-4A1E-B0BB-4B1FFF3FA616}.Release|Any CPU.ActiveCfg = Release|Any CPU
{80496B7B-068A-4A1E-B0BB-4B1FFF3FA616}.Release|Any CPU.Build.0 = Release|Any CPU
{B95C489C-8CB7-4DCF-8D5F-B9AEBDBBAF89}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B95C489C-8CB7-4DCF-8D5F-B9AEBDBBAF89}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B95C489C-8CB7-4DCF-8D5F-B9AEBDBBAF89}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B95C489C-8CB7-4DCF-8D5F-B9AEBDBBAF89}.Release|Any CPU.Build.0 = Release|Any CPU
{C2CF99A2-D35E-4AED-AFB9-C26960AF1D0D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C2CF99A2-D35E-4AED-AFB9-C26960AF1D0D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C2CF99A2-D35E-4AED-AFB9-C26960AF1D0D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C2CF99A2-D35E-4AED-AFB9-C26960AF1D0D}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -155,5 +167,6 @@ Global
{152D78F0-A642-4D0E-B3A8-2FC64FFA9714} = {95C16AED-FD57-42A0-86C3-2CF4300A4817}
{13E031E4-8A43-4B87-9D72-D70180C31C11} = {95C16AED-FD57-42A0-86C3-2CF4300A4817}
{3436A126-EDC9-4060-8952-9A1BE34CDD95} = {95C16AED-FD57-42A0-86C3-2CF4300A4817}
{C2CF99A2-D35E-4AED-AFB9-C26960AF1D0D} = {95C16AED-FD57-42A0-86C3-2CF4300A4817}
EndGlobalSection
EndGlobal
42 changes: 42 additions & 0 deletions src/Common/Authentication/Authentication.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
VisualStudioVersion = 12.0.40629.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Common.Authentication", "Common.Authentication\Common.Authentication.csproj", "{B95C489C-8CB7-4DCF-8D5F-B9AEBDBBAF89}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Common.Authentication.Tests", "Common.Authentication.Tests\Common.Authentication.Tests.csproj", "{C2CF99A2-D35E-4AED-AFB9-C26960AF1D0D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Net40-Debug|Any CPU = Net40-Debug|Any CPU
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no need for Net40 and Net45 build configurations (we should eventually remove them from AutoRest). In PowerShell it's just Debug and Release.

Net40-Release|Any CPU = Net40-Release|Any CPU
Net45-Debug|Any CPU = Net45-Debug|Any CPU
Net45-Release|Any CPU = Net45-Release|Any CPU
Portable-Debug|Any CPU = Portable-Debug|Any CPU
Portable-Release|Any CPU = Portable-Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{B95C489C-8CB7-4DCF-8D5F-B9AEBDBBAF89}.Net40-Debug|Any CPU.ActiveCfg = Net45-Release|Any CPU
{B95C489C-8CB7-4DCF-8D5F-B9AEBDBBAF89}.Net40-Release|Any CPU.ActiveCfg = Net45-Release|Any CPU
{B95C489C-8CB7-4DCF-8D5F-B9AEBDBBAF89}.Net45-Debug|Any CPU.ActiveCfg = Net45-Debug|Any CPU
{B95C489C-8CB7-4DCF-8D5F-B9AEBDBBAF89}.Net45-Debug|Any CPU.Build.0 = Net45-Debug|Any CPU
{B95C489C-8CB7-4DCF-8D5F-B9AEBDBBAF89}.Net45-Release|Any CPU.ActiveCfg = Net45-Release|Any CPU
{B95C489C-8CB7-4DCF-8D5F-B9AEBDBBAF89}.Net45-Release|Any CPU.Build.0 = Net45-Release|Any CPU
{B95C489C-8CB7-4DCF-8D5F-B9AEBDBBAF89}.Portable-Debug|Any CPU.ActiveCfg = Net45-Release|Any CPU
{B95C489C-8CB7-4DCF-8D5F-B9AEBDBBAF89}.Portable-Release|Any CPU.ActiveCfg = Net45-Release|Any CPU
{C2CF99A2-D35E-4AED-AFB9-C26960AF1D0D}.Net40-Debug|Any CPU.ActiveCfg = Net45-Release|Any CPU
{C2CF99A2-D35E-4AED-AFB9-C26960AF1D0D}.Net40-Release|Any CPU.ActiveCfg = Net45-Release|Any CPU
{C2CF99A2-D35E-4AED-AFB9-C26960AF1D0D}.Net45-Debug|Any CPU.ActiveCfg = Net45-Debug|Any CPU
{C2CF99A2-D35E-4AED-AFB9-C26960AF1D0D}.Net45-Debug|Any CPU.Build.0 = Net45-Debug|Any CPU
{C2CF99A2-D35E-4AED-AFB9-C26960AF1D0D}.Net45-Release|Any CPU.ActiveCfg = Net45-Release|Any CPU
{C2CF99A2-D35E-4AED-AFB9-C26960AF1D0D}.Net45-Release|Any CPU.Build.0 = Net45-Release|Any CPU
{C2CF99A2-D35E-4AED-AFB9-C26960AF1D0D}.Portable-Debug|Any CPU.ActiveCfg = Net45-Release|Any CPU
{C2CF99A2-D35E-4AED-AFB9-C26960AF1D0D}.Portable-Release|Any CPU.ActiveCfg = Net45-Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(TestCaseManagementSettings) = postSolution
CategoryFile = WindowsAzureLibraries.vsmdi
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
// ----------------------------------------------------------------------------------
//
// Copyright Microsoft Corporation
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ----------------------------------------------------------------------------------

using Microsoft.Azure.Common.Authentication;
using Microsoft.Azure.Common.Authentication.Factories;
using Microsoft.Azure.Common.Authentication.Models;
using Microsoft.Azure.Commands.Test.Utilities.Common;
using System;
using System.Collections.Generic;
using Xunit;

namespace Common.Authentication.Test
{
public class AuthenticationFactoryTests
{
[Fact]
public void VerifySubscriptionTokenCacheRemove()
{
var authFactory = new AuthenticationFactory
{
TokenProvider = new MockAccessTokenProvider("testtoken", "testuser")
};

var subscriptionId = Guid.NewGuid();

var credential = authFactory.GetSubscriptionCloudCredentials(new AzureContext
(
new AzureSubscription
{
Id = subscriptionId,
Properties = new Dictionary<AzureSubscription.Property, string>
{
{ AzureSubscription.Property.Tenants, "123"}
}
},
new AzureAccount
{
Id = "testuser",
Type = AzureAccount.AccountType.User,
Properties = new Dictionary<AzureAccount.Property, string>
{
{ AzureAccount.Property.Tenants, "123" }
}
},
AzureEnvironment.PublicEnvironments["AzureCloud"]
));

Assert.True(credential is AccessTokenCredential);
Assert.Equal(subscriptionId, new Guid(((AccessTokenCredential)credential).SubscriptionId));
}

[Fact]
public void VerifyValidateAuthorityFalseForOnPremise()
{
var authFactory = new AuthenticationFactory
{
TokenProvider = new MockAccessTokenProvider("testtoken", "testuser")
};

var subscriptionId = Guid.NewGuid();
var context = new AzureContext
(
new AzureSubscription
{
Id = subscriptionId,
Properties = new Dictionary<AzureSubscription.Property, string>
{
{ AzureSubscription.Property.Tenants, "123"}
}
},
new AzureAccount
{
Id = "testuser",
Type = AzureAccount.AccountType.User,
Properties = new Dictionary<AzureAccount.Property, string>
{
{ AzureAccount.Property.Tenants, "123" }
}
},
new AzureEnvironment
{
Name = "Katal",
OnPremise = true,
Endpoints = new Dictionary<AzureEnvironment.Endpoint, string>
{
{ AzureEnvironment.Endpoint.ActiveDirectory, "http://ad.com" },
{ AzureEnvironment.Endpoint.ActiveDirectoryServiceEndpointResourceId, "http://adresource.com" }
}
}
);

var credential = authFactory.Authenticate(context.Account, context.Environment, "common", null, ShowDialog.Always);

Assert.False(((MockAccessTokenProvider)authFactory.TokenProvider).AdalConfiguration.ValidateAuthority);
}
}
}
Loading