From 2df72072ad5bf4d40c1e20d96500593cd801b557 Mon Sep 17 00:00:00 2001 From: Chris Ross Date: Wed, 19 Jun 2019 10:16:20 -0700 Subject: [PATCH] Update facebook APIs to v3.3 #4684 (#11238) Update Google error message --- .../Certificate.Sample.csproj | 8 +-- .../Controllers/HomeController.cs | 12 ----- .../samples/Certificate.Sample/Startup.cs | 9 ++-- .../Views/Home/Index.cshtml | 1 - .../Facebook/src/FacebookDefaults.cs | 6 +-- .../Google/src/GoogleDefaults.cs | 1 + .../Google/src/GoogleHandler.cs | 2 +- .../samples/SocialSample/Startup.cs | 2 + .../Authentication/test/FacebookTests.cs | 6 +-- src/Security/Security.sln | 50 +++++++++++-------- 10 files changed, 46 insertions(+), 51 deletions(-) delete mode 100644 src/Security/Authentication/Certificate/samples/Certificate.Sample/Controllers/HomeController.cs delete mode 100644 src/Security/Authentication/Certificate/samples/Certificate.Sample/Views/Home/Index.cshtml diff --git a/src/Security/Authentication/Certificate/samples/Certificate.Sample/Certificate.Sample.csproj b/src/Security/Authentication/Certificate/samples/Certificate.Sample/Certificate.Sample.csproj index 2f085e5c41..338ec69518 100644 --- a/src/Security/Authentication/Certificate/samples/Certificate.Sample/Certificate.Sample.csproj +++ b/src/Security/Authentication/Certificate/samples/Certificate.Sample/Certificate.Sample.csproj @@ -1,20 +1,16 @@ - + netcoreapp3.0 OutOfProcess - - - - + - diff --git a/src/Security/Authentication/Certificate/samples/Certificate.Sample/Controllers/HomeController.cs b/src/Security/Authentication/Certificate/samples/Certificate.Sample/Controllers/HomeController.cs deleted file mode 100644 index 60be48074b..0000000000 --- a/src/Security/Authentication/Certificate/samples/Certificate.Sample/Controllers/HomeController.cs +++ /dev/null @@ -1,12 +0,0 @@ -using Microsoft.AspNetCore.Mvc; - -namespace Certificate.Sample.Controllers -{ - public class HomeController : Controller - { - public IActionResult Index() - { - return View(); - } - } -} diff --git a/src/Security/Authentication/Certificate/samples/Certificate.Sample/Startup.cs b/src/Security/Authentication/Certificate/samples/Certificate.Sample/Startup.cs index 14e2702e07..a45bcb93cf 100644 --- a/src/Security/Authentication/Certificate/samples/Certificate.Sample/Startup.cs +++ b/src/Security/Authentication/Certificate/samples/Certificate.Sample/Startup.cs @@ -4,7 +4,7 @@ using Microsoft.AspNetCore.Authentication.Certificate; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.Mvc.Authorization; +using Microsoft.AspNetCore.Http; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; @@ -38,8 +38,6 @@ namespace Certificate.Sample }); services.AddAuthorization(); - - services.AddMvc(config => { }); } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. @@ -54,7 +52,10 @@ namespace Certificate.Sample app.UseEndpoints(endpoints => { - endpoints.MapDefaultControllerRoute(); + endpoints.Map("{*url}", context => + { + return context.Response.WriteAsync($"Hello {context.User.Identity.Name}"); + }); }); } } diff --git a/src/Security/Authentication/Certificate/samples/Certificate.Sample/Views/Home/Index.cshtml b/src/Security/Authentication/Certificate/samples/Certificate.Sample/Views/Home/Index.cshtml deleted file mode 100644 index 5247bfe9c6..0000000000 --- a/src/Security/Authentication/Certificate/samples/Certificate.Sample/Views/Home/Index.cshtml +++ /dev/null @@ -1 +0,0 @@ -

Hello @User.Identity.Name

\ No newline at end of file diff --git a/src/Security/Authentication/Facebook/src/FacebookDefaults.cs b/src/Security/Authentication/Facebook/src/FacebookDefaults.cs index ff9bb40bf1..d85b99353a 100644 --- a/src/Security/Authentication/Facebook/src/FacebookDefaults.cs +++ b/src/Security/Authentication/Facebook/src/FacebookDefaults.cs @@ -10,10 +10,10 @@ namespace Microsoft.AspNetCore.Authentication.Facebook public static readonly string DisplayName = "Facebook"; // https://developers.facebook.com/docs/facebook-login/manually-build-a-login-flow#login - public static readonly string AuthorizationEndpoint = "https://www.facebook.com/v3.1/dialog/oauth"; + public static readonly string AuthorizationEndpoint = "https://www.facebook.com/v3.3/dialog/oauth"; - public static readonly string TokenEndpoint = "https://graph.facebook.com/v3.1/oauth/access_token"; + public static readonly string TokenEndpoint = "https://graph.facebook.com/v3.3/oauth/access_token"; - public static readonly string UserInformationEndpoint = "https://graph.facebook.com/v3.1/me"; + public static readonly string UserInformationEndpoint = "https://graph.facebook.com/v3.3/me"; } } diff --git a/src/Security/Authentication/Google/src/GoogleDefaults.cs b/src/Security/Authentication/Google/src/GoogleDefaults.cs index b4257f0619..5d87ac1bc0 100644 --- a/src/Security/Authentication/Google/src/GoogleDefaults.cs +++ b/src/Security/Authentication/Google/src/GoogleDefaults.cs @@ -19,6 +19,7 @@ namespace Microsoft.AspNetCore.Authentication.Google public static readonly string TokenEndpoint = "https://www.googleapis.com/oauth2/v4/token"; + // https://developers.google.com/apis-explorer/#search/oauth2/oauth2/v2/ public static readonly string UserInformationEndpoint = "https://www.googleapis.com/oauth2/v2/userinfo"; } } diff --git a/src/Security/Authentication/Google/src/GoogleHandler.cs b/src/Security/Authentication/Google/src/GoogleHandler.cs index 7d1df746f0..84f713f440 100644 --- a/src/Security/Authentication/Google/src/GoogleHandler.cs +++ b/src/Security/Authentication/Google/src/GoogleHandler.cs @@ -34,7 +34,7 @@ namespace Microsoft.AspNetCore.Authentication.Google var response = await Backchannel.SendAsync(request, Context.RequestAborted); if (!response.IsSuccessStatusCode) { - throw new HttpRequestException($"An error occurred when retrieving Google user information ({response.StatusCode}). Please check if the authentication information is correct and the corresponding Google+ API is enabled."); + throw new HttpRequestException($"An error occurred when retrieving Google user information ({response.StatusCode}). Please check if the authentication information is correct."); } using (var payload = JsonDocument.Parse(await response.Content.ReadAsStringAsync())) diff --git a/src/Security/Authentication/samples/SocialSample/Startup.cs b/src/Security/Authentication/samples/SocialSample/Startup.cs index 2c85c22c80..9ac713b448 100644 --- a/src/Security/Authentication/samples/SocialSample/Startup.cs +++ b/src/Security/Authentication/samples/SocialSample/Startup.cs @@ -117,6 +117,7 @@ namespace SocialSample }) // You must first create an app with GitHub and add its ID and Secret to your user-secrets. // https://github.com/settings/applications/ + // https://developer.github.com/apps/building-oauth-apps/authorizing-oauth-apps/ .AddOAuth("GitHub", "Github", o => { o.ClientId = Configuration["github:clientid"]; @@ -155,6 +156,7 @@ namespace SocialSample }) // You must first create an app with GitHub and add its ID and Secret to your user-secrets. // https://github.com/settings/applications/ + // https://developer.github.com/apps/building-oauth-apps/authorizing-oauth-apps/ .AddOAuth("GitHub-AccessToken", "GitHub AccessToken only", o => { o.ClientId = Configuration["github-token:clientid"]; diff --git a/src/Security/Authentication/test/FacebookTests.cs b/src/Security/Authentication/test/FacebookTests.cs index bd50a86de6..c0fc415c9c 100644 --- a/src/Security/Authentication/test/FacebookTests.cs +++ b/src/Security/Authentication/test/FacebookTests.cs @@ -225,7 +225,7 @@ namespace Microsoft.AspNetCore.Authentication.Facebook var transaction = await server.SendAsync("http://example.com/base/login"); Assert.Equal(HttpStatusCode.Redirect, transaction.Response.StatusCode); var location = transaction.Response.Headers.Location.AbsoluteUri; - Assert.Contains("https://www.facebook.com/v3.1/dialog/oauth", location); + Assert.Contains("https://www.facebook.com/v3.3/dialog/oauth", location); Assert.Contains("response_type=code", location); Assert.Contains("client_id=", location); Assert.Contains("redirect_uri=" + UrlEncoder.Default.Encode("http://example.com/base/signin-facebook"), location); @@ -257,7 +257,7 @@ namespace Microsoft.AspNetCore.Authentication.Facebook var transaction = await server.SendAsync("http://example.com/login"); Assert.Equal(HttpStatusCode.Redirect, transaction.Response.StatusCode); var location = transaction.Response.Headers.Location.AbsoluteUri; - Assert.Contains("https://www.facebook.com/v3.1/dialog/oauth", location); + Assert.Contains("https://www.facebook.com/v3.3/dialog/oauth", location); Assert.Contains("response_type=code", location); Assert.Contains("client_id=", location); Assert.Contains("redirect_uri=" + UrlEncoder.Default.Encode("http://example.com/signin-facebook"), location); @@ -291,7 +291,7 @@ namespace Microsoft.AspNetCore.Authentication.Facebook var transaction = await server.SendAsync("http://example.com/challenge"); Assert.Equal(HttpStatusCode.Redirect, transaction.Response.StatusCode); var location = transaction.Response.Headers.Location.AbsoluteUri; - Assert.Contains("https://www.facebook.com/v3.1/dialog/oauth", location); + Assert.Contains("https://www.facebook.com/v3.3/dialog/oauth", location); Assert.Contains("response_type=code", location); Assert.Contains("client_id=", location); Assert.Contains("redirect_uri=", location); diff --git a/src/Security/Security.sln b/src/Security/Security.sln index 3f0a69751e..55cad7f545 100644 --- a/src/Security/Security.sln +++ b/src/Security/Security.sln @@ -144,20 +144,23 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Authen EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Authentication.Negotiate.FunctionalTest", "Authentication\Negotiate\test\Negotiate.FunctionalTest\Microsoft.AspNetCore.Authentication.Negotiate.FunctionalTest.csproj", "{8991AEC8-49F3-4DF1-ADA9-00C13737E005}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Negotiate.Client", "Authentication\Negotiate\test\testassets\Negotiate.Client\Negotiate.Client.csproj", "{57DCE828-241E-437C-BEFC-AF4B6EB06D62}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Negotiate.Client", "Authentication\Negotiate\test\testassets\Negotiate.Client\Negotiate.Client.csproj", "{57DCE828-241E-437C-BEFC-AF4B6EB06D62}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Negotiate.Server", "Authentication\Negotiate\test\testassets\Negotiate.Server\Negotiate.Server.csproj", "{8771B5C8-4B96-4A40-A3FC-8CC7E16D7A82}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Negotiate.Server", "Authentication\Negotiate\test\testassets\Negotiate.Server\Negotiate.Server.csproj", "{8771B5C8-4B96-4A40-A3FC-8CC7E16D7A82}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Mvc", "..\Mvc\Mvc\src\Microsoft.AspNetCore.Mvc.csproj", "{27B5D7B5-75A6-4BE6-BD09-597044D06970}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Mvc.Core", "..\Mvc\Mvc.Core\src\Microsoft.AspNetCore.Mvc.Core.csproj", "{553F8C79-13AF-4993-99C1-D70F2143AD8E}" Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Certificate", "Certificate", "{4DF524BF-D9A9-46F2-882C-68C48FF5FF33}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Authentication.Certificate", "Authentication\Certificate\src\Microsoft.AspNetCore.Authentication.Certificate.csproj", "{2B88E3EA-6FBE-4690-A56E-0744FFAC9870}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Certificate.Sample", "Authentication\Certificate\samples\Certificate.Sample\Certificate.Sample.csproj", "{11F3B44F-DE5F-42C4-8EC9-1AA51FB89158}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.HeaderPropagation", "..\Middleware\HeaderPropagation\ref\Microsoft.AspNetCore.HeaderPropagation.csproj", "{9F9CBDD0-C8B3-4E79-B2B3-9ADE4AE08AEA}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Metadata", "..\Http\Metadata\src\Microsoft.AspNetCore.Metadata.csproj", "{7EB9FE73-A138-40FD-A339-8264B1871566}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore", "..\DefaultBuilder\src\Microsoft.AspNetCore.csproj", "{16C26D50-6849-4BA4-AEB6-E5C9AA2369A2}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.HostFiltering", "..\Middleware\HostFiltering\src\Microsoft.AspNetCore.HostFiltering.csproj", "{A665A1F8-D1A4-42AC-B8E9-71B6F57481D8}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Server.IIS", "..\Servers\IIS\IIS\src\Microsoft.AspNetCore.Server.IIS.csproj", "{666AFB4D-68A5-4621-BB55-2CD82F0FB1F8}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -393,14 +396,6 @@ Global {8771B5C8-4B96-4A40-A3FC-8CC7E16D7A82}.Debug|Any CPU.Build.0 = Debug|Any CPU {8771B5C8-4B96-4A40-A3FC-8CC7E16D7A82}.Release|Any CPU.ActiveCfg = Release|Any CPU {8771B5C8-4B96-4A40-A3FC-8CC7E16D7A82}.Release|Any CPU.Build.0 = Release|Any CPU - {27B5D7B5-75A6-4BE6-BD09-597044D06970}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {27B5D7B5-75A6-4BE6-BD09-597044D06970}.Debug|Any CPU.Build.0 = Debug|Any CPU - {27B5D7B5-75A6-4BE6-BD09-597044D06970}.Release|Any CPU.ActiveCfg = Release|Any CPU - {27B5D7B5-75A6-4BE6-BD09-597044D06970}.Release|Any CPU.Build.0 = Release|Any CPU - {553F8C79-13AF-4993-99C1-D70F2143AD8E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {553F8C79-13AF-4993-99C1-D70F2143AD8E}.Debug|Any CPU.Build.0 = Debug|Any CPU - {553F8C79-13AF-4993-99C1-D70F2143AD8E}.Release|Any CPU.ActiveCfg = Release|Any CPU - {553F8C79-13AF-4993-99C1-D70F2143AD8E}.Release|Any CPU.Build.0 = Release|Any CPU {2B88E3EA-6FBE-4690-A56E-0744FFAC9870}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {2B88E3EA-6FBE-4690-A56E-0744FFAC9870}.Debug|Any CPU.Build.0 = Debug|Any CPU {2B88E3EA-6FBE-4690-A56E-0744FFAC9870}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -409,10 +404,22 @@ Global {11F3B44F-DE5F-42C4-8EC9-1AA51FB89158}.Debug|Any CPU.Build.0 = Debug|Any CPU {11F3B44F-DE5F-42C4-8EC9-1AA51FB89158}.Release|Any CPU.ActiveCfg = Release|Any CPU {11F3B44F-DE5F-42C4-8EC9-1AA51FB89158}.Release|Any CPU.Build.0 = Release|Any CPU - {9F9CBDD0-C8B3-4E79-B2B3-9ADE4AE08AEA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {9F9CBDD0-C8B3-4E79-B2B3-9ADE4AE08AEA}.Debug|Any CPU.Build.0 = Debug|Any CPU - {9F9CBDD0-C8B3-4E79-B2B3-9ADE4AE08AEA}.Release|Any CPU.ActiveCfg = Release|Any CPU - {9F9CBDD0-C8B3-4E79-B2B3-9ADE4AE08AEA}.Release|Any CPU.Build.0 = Release|Any CPU + {7EB9FE73-A138-40FD-A339-8264B1871566}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {7EB9FE73-A138-40FD-A339-8264B1871566}.Debug|Any CPU.Build.0 = Debug|Any CPU + {7EB9FE73-A138-40FD-A339-8264B1871566}.Release|Any CPU.ActiveCfg = Release|Any CPU + {7EB9FE73-A138-40FD-A339-8264B1871566}.Release|Any CPU.Build.0 = Release|Any CPU + {16C26D50-6849-4BA4-AEB6-E5C9AA2369A2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {16C26D50-6849-4BA4-AEB6-E5C9AA2369A2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {16C26D50-6849-4BA4-AEB6-E5C9AA2369A2}.Release|Any CPU.ActiveCfg = Release|Any CPU + {16C26D50-6849-4BA4-AEB6-E5C9AA2369A2}.Release|Any CPU.Build.0 = Release|Any CPU + {A665A1F8-D1A4-42AC-B8E9-71B6F57481D8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A665A1F8-D1A4-42AC-B8E9-71B6F57481D8}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A665A1F8-D1A4-42AC-B8E9-71B6F57481D8}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A665A1F8-D1A4-42AC-B8E9-71B6F57481D8}.Release|Any CPU.Build.0 = Release|Any CPU + {666AFB4D-68A5-4621-BB55-2CD82F0FB1F8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {666AFB4D-68A5-4621-BB55-2CD82F0FB1F8}.Debug|Any CPU.Build.0 = Debug|Any CPU + {666AFB4D-68A5-4621-BB55-2CD82F0FB1F8}.Release|Any CPU.ActiveCfg = Release|Any CPU + {666AFB4D-68A5-4621-BB55-2CD82F0FB1F8}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -486,12 +493,13 @@ Global {8991AEC8-49F3-4DF1-ADA9-00C13737E005} = {A482E4FD-51C2-4061-8357-1E4757D6CF27} {57DCE828-241E-437C-BEFC-AF4B6EB06D62} = {A482E4FD-51C2-4061-8357-1E4757D6CF27} {8771B5C8-4B96-4A40-A3FC-8CC7E16D7A82} = {A482E4FD-51C2-4061-8357-1E4757D6CF27} - {27B5D7B5-75A6-4BE6-BD09-597044D06970} = {A3766414-EB5C-40F7-B031-121804ED5D0A} - {553F8C79-13AF-4993-99C1-D70F2143AD8E} = {A3766414-EB5C-40F7-B031-121804ED5D0A} {4DF524BF-D9A9-46F2-882C-68C48FF5FF33} = {79C549BA-2932-450A-B87D-635879361343} {2B88E3EA-6FBE-4690-A56E-0744FFAC9870} = {4DF524BF-D9A9-46F2-882C-68C48FF5FF33} {11F3B44F-DE5F-42C4-8EC9-1AA51FB89158} = {4DF524BF-D9A9-46F2-882C-68C48FF5FF33} - {9F9CBDD0-C8B3-4E79-B2B3-9ADE4AE08AEA} = {A3766414-EB5C-40F7-B031-121804ED5D0A} + {7EB9FE73-A138-40FD-A339-8264B1871566} = {A3766414-EB5C-40F7-B031-121804ED5D0A} + {16C26D50-6849-4BA4-AEB6-E5C9AA2369A2} = {A3766414-EB5C-40F7-B031-121804ED5D0A} + {A665A1F8-D1A4-42AC-B8E9-71B6F57481D8} = {A3766414-EB5C-40F7-B031-121804ED5D0A} + {666AFB4D-68A5-4621-BB55-2CD82F0FB1F8} = {A3766414-EB5C-40F7-B031-121804ED5D0A} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {ABF8089E-43D0-4010-84A7-7A9DCFE49357}