From 779264df3019086475add47bd8bd5e2013100892 Mon Sep 17 00:00:00 2001 From: Jennyf19 Date: Thu, 14 Jan 2021 15:04:49 -0800 Subject: [PATCH 1/3] rename folder --- Microsoft.Identity.Web.sln | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/Microsoft.Identity.Web.sln b/Microsoft.Identity.Web.sln index b96b2846b..d23238ab5 100644 --- a/Microsoft.Identity.Web.sln +++ b/Microsoft.Identity.Web.sln @@ -118,6 +118,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ToDoListModel", "tests\blaz EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "grpc", "tests\WebAppCallsWebApiCallsGraph\gRPC\grpc.csproj", "{10260252-4899-44D1-94A1-5BF34746A698}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "DevApps", "DevApps", "{9A51E6E0-A2B0-4D4D-9209-E73B8AD2B9C6}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -270,8 +272,8 @@ Global EndGlobalSection GlobalSection(NestedProjects) = preSolution {E58562C3-A55D-48C8-AA9C-7D0FA7839367} = {79310504-1334-4F14-93C4-1240913224BA} - {DA125992-5622-4D9D-B7AB-79CDC45A66B0} = {79310504-1334-4F14-93C4-1240913224BA} - {48D133A6-50D7-4783-9048-148E4B4E1353} = {79310504-1334-4F14-93C4-1240913224BA} + {DA125992-5622-4D9D-B7AB-79CDC45A66B0} = {9A51E6E0-A2B0-4D4D-9209-E73B8AD2B9C6} + {48D133A6-50D7-4783-9048-148E4B4E1353} = {9A51E6E0-A2B0-4D4D-9209-E73B8AD2B9C6} {D9C2BF2E-25C8-4BF0-9579-DF1F2AC7CA70} = {48D133A6-50D7-4783-9048-148E4B4E1353} {9EAE4CCD-EDEB-4FAE-B873-F24714F070A4} = {48D133A6-50D7-4783-9048-148E4B4E1353} {A6254A6A-B560-4DC1-8348-DED4D947ADCE} = {DA125992-5622-4D9D-B7AB-79CDC45A66B0} @@ -280,18 +282,18 @@ Global {F37646FF-C346-4FF5-A111-2269952AB376} = {79310504-1334-4F14-93C4-1240913224BA} {A9F4539F-51AB-4D98-9204-D76B336E0BE8} = {79310504-1334-4F14-93C4-1240913224BA} {893905EA-94D6-4F71-957A-43B194751DC7} = {D845507B-00E8-4506-954E-519CBC0B9F83} - {6AD49ED7-8975-4B2F-B916-BBA8ABA280D2} = {79310504-1334-4F14-93C4-1240913224BA} + {6AD49ED7-8975-4B2F-B916-BBA8ABA280D2} = {9A51E6E0-A2B0-4D4D-9209-E73B8AD2B9C6} {FF8EED45-187A-4FBD-875F-334D8DC44990} = {6AD49ED7-8975-4B2F-B916-BBA8ABA280D2} - {E7772A02-119A-41B1-9F97-CF6592120B7E} = {79310504-1334-4F14-93C4-1240913224BA} - {5F8B4227-A996-4C4F-802E-C671BB934C93} = {79310504-1334-4F14-93C4-1240913224BA} + {E7772A02-119A-41B1-9F97-CF6592120B7E} = {9A51E6E0-A2B0-4D4D-9209-E73B8AD2B9C6} + {5F8B4227-A996-4C4F-802E-C671BB934C93} = {9A51E6E0-A2B0-4D4D-9209-E73B8AD2B9C6} {744F5E2B-281C-4BC1-B9E1-D8C0530DC5E3} = {5F8B4227-A996-4C4F-802E-C671BB934C93} {05F00799-983F-4417-8365-A8215BDA51D1} = {E7772A02-119A-41B1-9F97-CF6592120B7E} {6B054485-C7F0-4D77-ABE3-B118407F76C7} = {E7772A02-119A-41B1-9F97-CF6592120B7E} {F18E5B8C-C6DA-4745-BF83-1CE40FCB95CA} = {E7772A02-119A-41B1-9F97-CF6592120B7E} {BC82D226-478F-44C3-B48F-AA24597320B7} = {20CDB9B2-D237-413A-8E76-A973597748B0} - {ED3F90E4-6BCE-40EA-91C3-64825EF20AB5} = {79310504-1334-4F14-93C4-1240913224BA} + {ED3F90E4-6BCE-40EA-91C3-64825EF20AB5} = {9A51E6E0-A2B0-4D4D-9209-E73B8AD2B9C6} {FA66AD23-CA57-4C2B-9A9E-2ABD91E89484} = {ED3F90E4-6BCE-40EA-91C3-64825EF20AB5} - {E571B66E-C693-445D-9DF8-A4C2CB9B69CD} = {79310504-1334-4F14-93C4-1240913224BA} + {E571B66E-C693-445D-9DF8-A4C2CB9B69CD} = {9A51E6E0-A2B0-4D4D-9209-E73B8AD2B9C6} {C6C1DF09-2A56-4A43-B74D-05587563847E} = {E571B66E-C693-445D-9DF8-A4C2CB9B69CD} {31AE5E2D-F2C3-4038-83F9-9AE6068F4742} = {E571B66E-C693-445D-9DF8-A4C2CB9B69CD} {69ECC686-3077-4E46-97F6-D287A4821FD4} = {E571B66E-C693-445D-9DF8-A4C2CB9B69CD} @@ -302,16 +304,17 @@ Global {9B8BE2D5-9E66-450F-94AB-8E8DD954C62C} = {79310504-1334-4F14-93C4-1240913224BA} {DE4BDA66-2918-4DB1-804A-4D5A8D7BAB3C} = {9B8BE2D5-9E66-450F-94AB-8E8DD954C62C} {3AA1208A-3F05-4420-A9C6-B5B7C09EFE4A} = {9B8BE2D5-9E66-450F-94AB-8E8DD954C62C} - {48C0BCBC-2490-4AC6-B931-48516524E809} = {79310504-1334-4F14-93C4-1240913224BA} + {48C0BCBC-2490-4AC6-B931-48516524E809} = {9A51E6E0-A2B0-4D4D-9209-E73B8AD2B9C6} {8A189B4F-10AF-45D7-9CF0-6029BB953500} = {48C0BCBC-2490-4AC6-B931-48516524E809} - {5DF5BBB5-FA7F-4A01-B8A1-37B8E5626F6D} = {79310504-1334-4F14-93C4-1240913224BA} - {2880F52B-7CC4-407B-8B6F-E00F4FD2EB75} = {79310504-1334-4F14-93C4-1240913224BA} + {5DF5BBB5-FA7F-4A01-B8A1-37B8E5626F6D} = {9A51E6E0-A2B0-4D4D-9209-E73B8AD2B9C6} + {2880F52B-7CC4-407B-8B6F-E00F4FD2EB75} = {9A51E6E0-A2B0-4D4D-9209-E73B8AD2B9C6} {832F7D3D-4599-41EC-973B-F30869EFEEF6} = {2880F52B-7CC4-407B-8B6F-E00F4FD2EB75} - {0E188C73-95E7-44D8-96F5-25AAF8BA1AE4} = {79310504-1334-4F14-93C4-1240913224BA} + {0E188C73-95E7-44D8-96F5-25AAF8BA1AE4} = {9A51E6E0-A2B0-4D4D-9209-E73B8AD2B9C6} {4EBD4DBB-B71C-4102-9031-72BA236B4B0F} = {0E188C73-95E7-44D8-96F5-25AAF8BA1AE4} {357D32E9-5AD8-4D26-8393-69F90394DF99} = {0E188C73-95E7-44D8-96F5-25AAF8BA1AE4} {8DC4213C-4C13-44AF-9A88-B53EEE2E9132} = {0E188C73-95E7-44D8-96F5-25AAF8BA1AE4} {10260252-4899-44D1-94A1-5BF34746A698} = {DA125992-5622-4D9D-B7AB-79CDC45A66B0} + {9A51E6E0-A2B0-4D4D-9209-E73B8AD2B9C6} = {79310504-1334-4F14-93C4-1240913224BA} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {F4FA8C4C-3251-41CC-939B-7892F5798549} From 43cb4e0ea9fb60739a0d412b2820c802779be21a Mon Sep 17 00:00:00 2001 From: Jennyf19 Date: Thu, 14 Jan 2021 20:29:24 -0800 Subject: [PATCH 2/3] add azure functions test app --- Microsoft.Identity.Web.sln | 10 +++++ tests/AzureFunctions/SampleFunc.sln | 25 +++++++++++ tests/AzureFunctions/SampleFunc/SampleFunc.cs | 45 +++++++++++++++++++ .../SampleFunc/SampleFunc.csproj | 22 +++++++++ tests/AzureFunctions/SampleFunc/Startup.cs | 33 ++++++++++++++ tests/AzureFunctions/SampleFunc/host.json | 11 +++++ .../SampleFunc/local.settings.json.sample | 13 ++++++ 7 files changed, 159 insertions(+) create mode 100644 tests/AzureFunctions/SampleFunc.sln create mode 100644 tests/AzureFunctions/SampleFunc/SampleFunc.cs create mode 100644 tests/AzureFunctions/SampleFunc/SampleFunc.csproj create mode 100644 tests/AzureFunctions/SampleFunc/Startup.cs create mode 100644 tests/AzureFunctions/SampleFunc/host.json create mode 100644 tests/AzureFunctions/SampleFunc/local.settings.json.sample diff --git a/Microsoft.Identity.Web.sln b/Microsoft.Identity.Web.sln index d23238ab5..4b877583b 100644 --- a/Microsoft.Identity.Web.sln +++ b/Microsoft.Identity.Web.sln @@ -120,6 +120,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "grpc", "tests\WebAppCallsWe EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "DevApps", "DevApps", "{9A51E6E0-A2B0-4D4D-9209-E73B8AD2B9C6}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "AzureFunctions", "AzureFunctions", "{2A2EB8D3-88F2-4FA2-8DDB-56B1F4755475}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SampleFunc", "tests\AzureFunctions\SampleFunc\SampleFunc.csproj", "{BE7E71AD-7272-4431-B50D-357C61CE2F8F}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -266,6 +270,10 @@ Global {10260252-4899-44D1-94A1-5BF34746A698}.Debug|Any CPU.Build.0 = Debug|Any CPU {10260252-4899-44D1-94A1-5BF34746A698}.Release|Any CPU.ActiveCfg = Release|Any CPU {10260252-4899-44D1-94A1-5BF34746A698}.Release|Any CPU.Build.0 = Release|Any CPU + {BE7E71AD-7272-4431-B50D-357C61CE2F8F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {BE7E71AD-7272-4431-B50D-357C61CE2F8F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {BE7E71AD-7272-4431-B50D-357C61CE2F8F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {BE7E71AD-7272-4431-B50D-357C61CE2F8F}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -315,6 +323,8 @@ Global {8DC4213C-4C13-44AF-9A88-B53EEE2E9132} = {0E188C73-95E7-44D8-96F5-25AAF8BA1AE4} {10260252-4899-44D1-94A1-5BF34746A698} = {DA125992-5622-4D9D-B7AB-79CDC45A66B0} {9A51E6E0-A2B0-4D4D-9209-E73B8AD2B9C6} = {79310504-1334-4F14-93C4-1240913224BA} + {2A2EB8D3-88F2-4FA2-8DDB-56B1F4755475} = {9A51E6E0-A2B0-4D4D-9209-E73B8AD2B9C6} + {BE7E71AD-7272-4431-B50D-357C61CE2F8F} = {2A2EB8D3-88F2-4FA2-8DDB-56B1F4755475} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {F4FA8C4C-3251-41CC-939B-7892F5798549} diff --git a/tests/AzureFunctions/SampleFunc.sln b/tests/AzureFunctions/SampleFunc.sln new file mode 100644 index 000000000..50e6b4d71 --- /dev/null +++ b/tests/AzureFunctions/SampleFunc.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.808.4 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SampleFunc", "SampleFunc\SampleFunc.csproj", "{C9A76FF7-5E35-4C96-AEFF-80F1B2EF7163}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {C9A76FF7-5E35-4C96-AEFF-80F1B2EF7163}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C9A76FF7-5E35-4C96-AEFF-80F1B2EF7163}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C9A76FF7-5E35-4C96-AEFF-80F1B2EF7163}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C9A76FF7-5E35-4C96-AEFF-80F1B2EF7163}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {10B2A9EB-3E1F-4A42-ABAD-13C93152FB67} + EndGlobalSection +EndGlobal diff --git a/tests/AzureFunctions/SampleFunc/SampleFunc.cs b/tests/AzureFunctions/SampleFunc/SampleFunc.cs new file mode 100644 index 000000000..9c853a820 --- /dev/null +++ b/tests/AzureFunctions/SampleFunc/SampleFunc.cs @@ -0,0 +1,45 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System.Threading.Tasks; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Azure.WebJobs; +using Microsoft.Azure.WebJobs.Extensions.Http; +using Microsoft.AspNetCore.Http; +using Microsoft.Extensions.Logging; +using Microsoft.Identity.Web; + +namespace SampleFunc +{ + public class SampleFunc + { + private readonly ITokenAcquisition _tokenAcquisition; + + public SampleFunc(ITokenAcquisition tokenAcquisition) + { + _tokenAcquisition = tokenAcquisition; + } + + [FunctionName("SampleFunc")] + public async Task Run( + [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req, + ILogger log) + { + log.LogInformation("C# HTTP trigger function processed a request."); + + var (authenticationStatus, authenticationResponse) = + await req.HttpContext.AuthenticateAzureFunctionAsync(); + if (!authenticationStatus) return authenticationResponse; + + var token = await _tokenAcquisition.GetAccessTokenForAppAsync("https://graph.microsoft.com/.default" ); + + string name = req.HttpContext.User.Identity.IsAuthenticated ? req.HttpContext.User.Identity.Name : null; + + string responseMessage = string.IsNullOrEmpty(name) + ? "This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response." + : $"Hello, {name}. This HTTP triggered function executed successfully."; + + return new OkObjectResult(responseMessage); + } + } +} diff --git a/tests/AzureFunctions/SampleFunc/SampleFunc.csproj b/tests/AzureFunctions/SampleFunc/SampleFunc.csproj new file mode 100644 index 000000000..9ac6ba265 --- /dev/null +++ b/tests/AzureFunctions/SampleFunc/SampleFunc.csproj @@ -0,0 +1,22 @@ + + + netcoreapp3.1 + v3 + + + + + + + + + + + PreserveNewest + + + PreserveNewest + Never + + + \ No newline at end of file diff --git a/tests/AzureFunctions/SampleFunc/Startup.cs b/tests/AzureFunctions/SampleFunc/Startup.cs new file mode 100644 index 000000000..1d1b3a433 --- /dev/null +++ b/tests/AzureFunctions/SampleFunc/Startup.cs @@ -0,0 +1,33 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using Microsoft.Azure.Functions.Extensions.DependencyInjection; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Identity.Web; + +[assembly: FunctionsStartup(typeof(SampleFunc.Startup))] + +namespace SampleFunc +{ + public class Startup : FunctionsStartup + { + public Startup() + { + } + + public override void Configure(IFunctionsHostBuilder builder) + { + // This is configuration from environment variables, settings.json etc. + var configuration = builder.GetContext().Configuration; + + builder.Services.AddAuthentication(sharedOptions => + { + sharedOptions.DefaultScheme = Constants.Bearer; + sharedOptions.DefaultChallengeScheme = Constants.Bearer; + }) + .AddMicrosoftIdentityWebApi(configuration) + .EnableTokenAcquisitionToCallDownstreamApi() + .AddInMemoryTokenCaches(); + } + } +} diff --git a/tests/AzureFunctions/SampleFunc/host.json b/tests/AzureFunctions/SampleFunc/host.json new file mode 100644 index 000000000..0b77e3716 --- /dev/null +++ b/tests/AzureFunctions/SampleFunc/host.json @@ -0,0 +1,11 @@ +{ + "logging": { + "applicationInsights": { + "samplingExcludedTypes": "Request", + "samplingSettings": { + "isEnabled": true + } + } + }, + "version": "2.0" +} diff --git a/tests/AzureFunctions/SampleFunc/local.settings.json.sample b/tests/AzureFunctions/SampleFunc/local.settings.json.sample new file mode 100644 index 000000000..421386dd2 --- /dev/null +++ b/tests/AzureFunctions/SampleFunc/local.settings.json.sample @@ -0,0 +1,13 @@ +{ + "IsEncrypted": false, + "Values": { + "AzureWebJobsStorage": "UseDevelopmentStorage=true", + "FUNCTIONS_WORKER_RUNTIME": "dotnet", + "AzureAd:Instance": "https://login.microsoftonline.com/", + "AzureAd:Domain": ".onmicrosoft.com", + "AzureAd:TenantId": "", + "AzureAd:ClientId": "", + "AzureAd:ClientSecret": "", + "AzureAd:AllowWebApiToBeAuthorizedByACL": true + } +} \ No newline at end of file From cca57674b2d31b42a53a5376670831fa4aa76f61 Mon Sep 17 00:00:00 2001 From: jennyf19 Date: Fri, 15 Jan 2021 09:19:54 -0800 Subject: [PATCH 3/3] fix merge --- src/Microsoft.Identity.Web/TempDataLoginErrorAccessor.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Microsoft.Identity.Web/TempDataLoginErrorAccessor.cs b/src/Microsoft.Identity.Web/TempDataLoginErrorAccessor.cs index e2c6e8cf3..da5e6812f 100644 --- a/src/Microsoft.Identity.Web/TempDataLoginErrorAccessor.cs +++ b/src/Microsoft.Identity.Web/TempDataLoginErrorAccessor.cs @@ -73,6 +73,7 @@ private class EmptyLoginErrorAccessor : ILoginErrorAccessor public void SetMessage(HttpContext context, string? message) { + // This is empty. } } }