From 61d03b9316bc81d24f9e0f561a26e4eea064bb6a Mon Sep 17 00:00:00 2001 From: Troy Dai Date: Mon, 11 Jul 2016 11:46:33 -0700 Subject: [PATCH] Update OIDC Azure Sample 1. Add set up instructions. 2. Add user secret tools. 3. Clean up codes. --- .../OpenIdConnect.AzureAdSample/Program.cs | 1 - samples/OpenIdConnect.AzureAdSample/Readme.md | 20 +++++++++++++++++++ .../OpenIdConnect.AzureAdSample/Startup.cs | 3 +-- .../OpenIdConnect.AzureAdSample/project.json | 5 +++-- 4 files changed, 24 insertions(+), 5 deletions(-) create mode 100644 samples/OpenIdConnect.AzureAdSample/Readme.md diff --git a/samples/OpenIdConnect.AzureAdSample/Program.cs b/samples/OpenIdConnect.AzureAdSample/Program.cs index 254668022d..11d1fbeafb 100644 --- a/samples/OpenIdConnect.AzureAdSample/Program.cs +++ b/samples/OpenIdConnect.AzureAdSample/Program.cs @@ -1,6 +1,5 @@ using System.IO; using Microsoft.AspNetCore.Hosting; -using Microsoft.Extensions.Configuration; namespace OpenIdConnect.AzureAdSample { diff --git a/samples/OpenIdConnect.AzureAdSample/Readme.md b/samples/OpenIdConnect.AzureAdSample/Readme.md new file mode 100644 index 0000000000..37dda75a72 --- /dev/null +++ b/samples/OpenIdConnect.AzureAdSample/Readme.md @@ -0,0 +1,20 @@ +# How to set up the sample locally + +## Set up [Azure Active Directory](https://azure.microsoft.com/en-us/documentation/services/active-directory/) + +1. Create your own Azure Active Directory (AD). Save the "tenent name". +2. Add a new Application: in the Azure AD portal, select Application, and click Add in the drawer. +3. Set the sign-on url to `http://localhost:42023`. +4. Select the newly created Application, navigate to the Configure tab. +5. Find and save the "Client Id" +8. In the keys section add a new key. A key value will be generated. Save the value as "Client Secret" + +## Configure the local environment +1. Set environment ASPNETCORE_ENVIRONMENT to DEVELOPMENMT. ([Working with Multiple Environments](https://docs.asp.net/en/latest/fundamentals/environments.html)) +2. Set up user secrets: +``` +dotnet user-secrets set oidc:clientid +dotnet user-secrets set oidc:clientsecret +dotnet user-secrets set oidc:authority https://login.windows.net/.onmicrosoft.com +``` + diff --git a/samples/OpenIdConnect.AzureAdSample/Startup.cs b/samples/OpenIdConnect.AzureAdSample/Startup.cs index f27a524928..8a2b7f4412 100644 --- a/samples/OpenIdConnect.AzureAdSample/Startup.cs +++ b/samples/OpenIdConnect.AzureAdSample/Startup.cs @@ -7,7 +7,6 @@ using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Authentication; using Microsoft.AspNetCore.Http.Extensions; -using Microsoft.AspNetCore.Http.Features.Authentication; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; @@ -88,7 +87,7 @@ namespace OpenIdConnect.AzureAdSample { var request = context.HttpContext.Request; var currentUri = UriHelper.BuildAbsolute(request.Scheme, request.Host, request.PathBase, request.Path); - var credential = new ClientCredential(clientId, clientSecret); + var credential = new ClientCredential(clientId, clientSecret); var authContext = new AuthenticationContext(authority, AuthPropertiesTokenCache.ForCodeRedemption(context.Properties)); var result = await authContext.AcquireTokenByAuthorizationCodeAsync( diff --git a/samples/OpenIdConnect.AzureAdSample/project.json b/samples/OpenIdConnect.AzureAdSample/project.json index adb6a845a0..6aee5073f2 100644 --- a/samples/OpenIdConnect.AzureAdSample/project.json +++ b/samples/OpenIdConnect.AzureAdSample/project.json @@ -31,9 +31,10 @@ }, "userSecretsId": "aspnet5-OpenIdConnectSample-20151210110318", "tools": { - "Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-*" + "Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-*", + "Microsoft.Extensions.SecretManager.Tools": "1.0.0-*" }, "scripts": { "postpublish": "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" } -} \ No newline at end of file +}