Skip to content

Commit

Permalink
Changed to add MSAL support
Browse files Browse the repository at this point in the history
  • Loading branch information
ShubhaVijayasarathy committed Jun 20, 2019
1 parent 2c7a9e3 commit 3684ee8
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 30 deletions.
2 changes: 1 addition & 1 deletion samples/DotNet/Rbac/AzureEventHubsSDK/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Microsoft.IdentityModel.Clients.ActiveDirectory" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.14.2.11" newVersion="3.14.2.11" />
<bindingRedirect oldVersion="0.0.0.0-5.1.0.0" newVersion="5.1.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.IdentityModel.Clients.ActiveDirectory.Platform" publicKeyToken="31bf3856ad364e35" culture="neutral" />
Expand Down
37 changes: 16 additions & 21 deletions samples/DotNet/Rbac/AzureEventHubsSDK/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using System.Text;
using System.Threading.Tasks;
using Microsoft.Azure.EventHubs;
using Microsoft.IdentityModel.Clients.ActiveDirectory;
using Microsoft.Identity.Client;

namespace EventHubsSenderReceiverRbac
{
Expand Down Expand Up @@ -68,20 +68,17 @@ static async Task ManagedIdentityScenarioAsync()
}

static async Task UserInteractiveLoginScenarioAsync()
{
{
var ehClient = EventHubClient.CreateWithAzureActiveDirectory(
new Uri($"sb://{EventHubNamespace}/"),
EventHubName,
async (audience, authority, state) =>
{
var authContext = new AuthenticationContext(authority);
var app = PublicClientApplicationBuilder.Create(ClientId)
.WithRedirectUri(ReplyUrl)
.Build();
var authResult = await authContext.AcquireTokenAsync(
audience,
ClientId,
new Uri(ReplyUrl),
new PlatformParameters(PromptBehavior.Auto),
UserIdentifier.AnyUser);
var authResult = await app.AcquireTokenInteractive(new string[] { $"{audience}/.default" }).ExecuteAsync();
return authResult.AccessToken;
},
Expand All @@ -93,17 +90,16 @@ static async Task UserInteractiveLoginScenarioAsync()
static async Task ClientAssertionCertScenarioAsync()
{
X509Certificate2 certificate = GetCertificate();
ClientAssertionCertificate clientAssertionCertificate = new ClientAssertionCertificate(ClientId, certificate);

TokenProvider tp = TokenProvider.CreateAzureActiveDirectoryTokenProvider(
async (audience, authority, state) =>
{
var authContext = new AuthenticationContext(authority);
var authResult = await authContext.AcquireTokenAsync(
audience,
clientAssertionCertificate);
IConfidentialClientApplication app = ConfidentialClientApplicationBuilder.Create(ClientId)
.WithAuthority(authority)
.WithCertificate(certificate)
.Build();
var authResult = await app.AcquireTokenForClient(new string[] { $"{audience}/.default" }).ExecuteAsync();
return authResult.AccessToken;
});

Expand All @@ -113,16 +109,15 @@ static async Task ClientAssertionCertScenarioAsync()

static async Task ClientCredentialsScenarioAsync()
{
ClientCredential clientCredential = new ClientCredential(ClientId, ConfigurationManager.AppSettings["clientSecret"]);
TokenProvider tp = TokenProvider.CreateAzureActiveDirectoryTokenProvider(
async (audience, authority, state) =>
{
var authContext = new AuthenticationContext(authority);
var authResult = await authContext.AcquireTokenAsync(
audience,
clientCredential);
IConfidentialClientApplication app = ConfidentialClientApplicationBuilder.Create(ClientId)
.WithAuthority(authority)
.WithClientSecret(ConfigurationManager.AppSettings["clientSecret"])
.Build();
var authResult = await app.AcquireTokenForClient(new string[] { $"{audience}/.default" }).ExecuteAsync();
return authResult.AccessToken;
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@
<Reference Include="Microsoft.Azure.Services.AppAuthentication, Version=1.0.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>packages\Microsoft.Azure.Services.AppAuthentication.1.0.3\lib\net452\Microsoft.Azure.Services.AppAuthentication.dll</HintPath>
</Reference>
<Reference Include="Microsoft.IdentityModel.Clients.ActiveDirectory, Version=3.14.2.11, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>packages\Microsoft.IdentityModel.Clients.ActiveDirectory.3.14.2\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.dll</HintPath>
<Reference Include="Microsoft.Identity.Client, Version=4.0.0.0, Culture=neutral, PublicKeyToken=0a613f4dd989e8ae, processorArchitecture=MSIL">
<HintPath>packages\Microsoft.Identity.Client.4.0.0\lib\net45\Microsoft.Identity.Client.dll</HintPath>
</Reference>
<Reference Include="Microsoft.IdentityModel.Clients.ActiveDirectory.Platform, Version=3.14.2.11, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>packages\Microsoft.IdentityModel.Clients.ActiveDirectory.3.14.2\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.Platform.dll</HintPath>
<Reference Include="Microsoft.IdentityModel.Clients.ActiveDirectory, Version=5.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>packages\Microsoft.IdentityModel.Clients.ActiveDirectory.5.1.0\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.dll</HintPath>
</Reference>
<Reference Include="Microsoft.IdentityModel.JsonWebTokens, Version=5.4.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>packages\Microsoft.IdentityModel.JsonWebTokens.5.4.0\lib\net461\Microsoft.IdentityModel.JsonWebTokens.dll</HintPath>
Expand Down Expand Up @@ -107,7 +107,9 @@
<Reference Include="System.Security.Cryptography.X509Certificates, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>packages\System.Security.Cryptography.X509Certificates.4.3.0\lib\net461\System.Security.Cryptography.X509Certificates.dll</HintPath>
</Reference>
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
<Reference Include="System.Xml.Linq" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
Expand Down
5 changes: 1 addition & 4 deletions samples/DotNet/Rbac/AzureEventHubsSDK/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
<package id="Microsoft.Azure.Amqp" version="2.4.2" targetFramework="net462" />
<package id="Microsoft.Azure.EventHubs" version="3.0.0-dev.20190618.1" targetFramework="net462" />
<package id="Microsoft.Azure.Services.AppAuthentication" version="1.0.3" targetFramework="net462" />
<package id="Microsoft.IdentityModel.Clients.ActiveDirectory" version="3.14.2" targetFramework="net462" />
<package id="Microsoft.IdentityModel.JsonWebTokens" version="5.4.0" targetFramework="net462" />
<package id="Microsoft.IdentityModel.Logging" version="5.4.0" targetFramework="net462" />
<package id="Microsoft.IdentityModel.Tokens" version="5.4.0" targetFramework="net462" />
<package id="Microsoft.Identity.Client" version="4.0.0" targetFramework="net462" />
<package id="Newtonsoft.Json" version="10.0.1" targetFramework="net462" />
<package id="System.Diagnostics.DiagnosticSource" version="4.5.1" targetFramework="net462" />
<package id="System.IdentityModel.Tokens.Jwt" version="5.4.0" targetFramework="net462" />
Expand Down

0 comments on commit 3684ee8

Please sign in to comment.