-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
b1cb6aa
Moving Common.Authentication to Powershell repo.
04daf66
Fixed build breaks in Common.Authentication
065a994
Merge branch 'clu' of github.com:Azure/azure-powershell into clu
2397d05
Fixed wrong ADAL version reference in Authentication/Common.Authentic…
6b27261
Fixed build breaks in Authentication tests
0c53e08
Fixed failing tests in Authentication.
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
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 |
108 changes: 108 additions & 0 deletions
108
src/Common/Authentication/Common.Authentication.Tests/AuthenticationFactoryTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.