From eabdd4581604d4e0f8d668c30bd5aa5e92e78a8f Mon Sep 17 00:00:00 2001 From: Troy Dai Date: Mon, 25 Jul 2016 22:28:26 -0700 Subject: [PATCH] Improve code readability for Authentication.Google --- .../GoogleAppBuilderExtensions.cs | 7 +++++-- .../GoogleDefaults.cs | 5 ++++- .../GoogleHandler.cs | 15 +++++++++++---- .../GoogleHelper.cs | 1 - .../GoogleMiddleware.cs | 5 ++++- 5 files changed, 24 insertions(+), 9 deletions(-) diff --git a/src/Microsoft.AspNetCore.Authentication.Google/GoogleAppBuilderExtensions.cs b/src/Microsoft.AspNetCore.Authentication.Google/GoogleAppBuilderExtensions.cs index fe693a61b7..85a193d82b 100644 --- a/src/Microsoft.AspNetCore.Authentication.Google/GoogleAppBuilderExtensions.cs +++ b/src/Microsoft.AspNetCore.Authentication.Google/GoogleAppBuilderExtensions.cs @@ -13,7 +13,8 @@ namespace Microsoft.AspNetCore.Builder public static class GoogleAppBuilderExtensions { /// - /// Adds the middleware to the specified , which enables Google authentication capabilities. + /// Adds the middleware to the specified , + /// which enables Google authentication capabilities. /// /// The to add the middleware to. /// A reference to this instance after the operation has completed. @@ -28,7 +29,8 @@ namespace Microsoft.AspNetCore.Builder } /// - /// Adds the middleware to the specified , which enables Google authentication capabilities. + /// Adds the middleware to the specified , + /// which enables Google authentication capabilities. /// /// The to add the middleware to. /// A that specifies options for the middleware. @@ -39,6 +41,7 @@ namespace Microsoft.AspNetCore.Builder { throw new ArgumentNullException(nameof(app)); } + if (options == null) { throw new ArgumentNullException(nameof(options)); diff --git a/src/Microsoft.AspNetCore.Authentication.Google/GoogleDefaults.cs b/src/Microsoft.AspNetCore.Authentication.Google/GoogleDefaults.cs index c17ff6b2ab..ef6fae9bc1 100644 --- a/src/Microsoft.AspNetCore.Authentication.Google/GoogleDefaults.cs +++ b/src/Microsoft.AspNetCore.Authentication.Google/GoogleDefaults.cs @@ -3,9 +3,12 @@ namespace Microsoft.AspNetCore.Authentication.Google { + /// + /// Default values for Google authentication + /// public static class GoogleDefaults { - public const string AuthenticationScheme = "Google"; + public static readonly string AuthenticationScheme = "Google"; public static readonly string AuthorizationEndpoint = "https://accounts.google.com/o/oauth2/auth"; diff --git a/src/Microsoft.AspNetCore.Authentication.Google/GoogleHandler.cs b/src/Microsoft.AspNetCore.Authentication.Google/GoogleHandler.cs index affde917aa..6e3ee36939 100644 --- a/src/Microsoft.AspNetCore.Authentication.Google/GoogleHandler.cs +++ b/src/Microsoft.AspNetCore.Authentication.Google/GoogleHandler.cs @@ -22,7 +22,10 @@ namespace Microsoft.AspNetCore.Authentication.Google { } - protected override async Task CreateTicketAsync(ClaimsIdentity identity, AuthenticationProperties properties, OAuthTokenResponse tokens) + protected override async Task CreateTicketAsync( + ClaimsIdentity identity, + AuthenticationProperties properties, + OAuthTokenResponse tokens) { // Get the Google user var request = new HttpRequestMessage(HttpMethod.Get, Options.UserInformationEndpoint); @@ -33,7 +36,8 @@ namespace Microsoft.AspNetCore.Authentication.Google var payload = JObject.Parse(await response.Content.ReadAsStringAsync()); - var ticket = new AuthenticationTicket(new ClaimsPrincipal(identity), properties, Options.AuthenticationScheme); + var principal = new ClaimsPrincipal(identity); + var ticket = new AuthenticationTicket(principal, properties, Options.AuthenticationScheme); var context = new OAuthCreatingTicketContext(ticket, Context, Options, Backchannel, tokens, payload); var identifier = GoogleHelper.GetId(payload); @@ -100,8 +104,11 @@ namespace Microsoft.AspNetCore.Authentication.Google return authorizationEndpoint; } - private static void AddQueryString(IDictionary queryStrings, AuthenticationProperties properties, - string name, string defaultValue = null) + private static void AddQueryString( + IDictionary queryStrings, + AuthenticationProperties properties, + string name, + string defaultValue = null) { string value; if (!properties.Items.TryGetValue(name, out value)) diff --git a/src/Microsoft.AspNetCore.Authentication.Google/GoogleHelper.cs b/src/Microsoft.AspNetCore.Authentication.Google/GoogleHelper.cs index 0a763d5696..336536c512 100644 --- a/src/Microsoft.AspNetCore.Authentication.Google/GoogleHelper.cs +++ b/src/Microsoft.AspNetCore.Authentication.Google/GoogleHelper.cs @@ -2,7 +2,6 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using Microsoft.Extensions.Internal; using Newtonsoft.Json.Linq; namespace Microsoft.AspNetCore.Authentication.Google diff --git a/src/Microsoft.AspNetCore.Authentication.Google/GoogleMiddleware.cs b/src/Microsoft.AspNetCore.Authentication.Google/GoogleMiddleware.cs index eb98e447b3..5f8afaff2f 100644 --- a/src/Microsoft.AspNetCore.Authentication.Google/GoogleMiddleware.cs +++ b/src/Microsoft.AspNetCore.Authentication.Google/GoogleMiddleware.cs @@ -69,7 +69,10 @@ namespace Microsoft.AspNetCore.Authentication.Google /// /// Provides the object for processing authentication-related requests. /// - /// An configured with the supplied to the constructor. + /// + /// An configured with the + /// supplied to the constructor. + /// protected override AuthenticationHandler CreateHandler() { return new GoogleHandler(Backchannel);