Improve code readability for Authentication.Google

This commit is contained in:
Troy Dai 2016-07-25 22:28:26 -07:00
parent 7b7da43fd8
commit eabdd45816
5 changed files with 24 additions and 9 deletions

View File

@ -13,7 +13,8 @@ namespace Microsoft.AspNetCore.Builder
public static class GoogleAppBuilderExtensions
{
/// <summary>
/// Adds the <see cref="GoogleMiddleware"/> middleware to the specified <see cref="IApplicationBuilder"/>, which enables Google authentication capabilities.
/// Adds the <see cref="GoogleMiddleware"/> middleware to the specified <see cref="IApplicationBuilder"/>,
/// which enables Google authentication capabilities.
/// </summary>
/// <param name="app">The <see cref="IApplicationBuilder"/> to add the middleware to.</param>
/// <returns>A reference to this instance after the operation has completed.</returns>
@ -28,7 +29,8 @@ namespace Microsoft.AspNetCore.Builder
}
/// <summary>
/// Adds the <see cref="GoogleMiddleware"/> middleware to the specified <see cref="IApplicationBuilder"/>, which enables Google authentication capabilities.
/// Adds the <see cref="GoogleMiddleware"/> middleware to the specified <see cref="IApplicationBuilder"/>,
/// which enables Google authentication capabilities.
/// </summary>
/// <param name="app">The <see cref="IApplicationBuilder"/> to add the middleware to.</param>
/// <param name="options">A <see cref="GoogleOptions"/> that specifies options for the middleware.</param>
@ -39,6 +41,7 @@ namespace Microsoft.AspNetCore.Builder
{
throw new ArgumentNullException(nameof(app));
}
if (options == null)
{
throw new ArgumentNullException(nameof(options));

View File

@ -3,9 +3,12 @@
namespace Microsoft.AspNetCore.Authentication.Google
{
/// <summary>
/// Default values for Google authentication
/// </summary>
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";

View File

@ -22,7 +22,10 @@ namespace Microsoft.AspNetCore.Authentication.Google
{
}
protected override async Task<AuthenticationTicket> CreateTicketAsync(ClaimsIdentity identity, AuthenticationProperties properties, OAuthTokenResponse tokens)
protected override async Task<AuthenticationTicket> 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<string, string> queryStrings, AuthenticationProperties properties,
string name, string defaultValue = null)
private static void AddQueryString(
IDictionary<string, string> queryStrings,
AuthenticationProperties properties,
string name,
string defaultValue = null)
{
string value;
if (!properties.Items.TryGetValue(name, out value))

View File

@ -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

View File

@ -69,7 +69,10 @@ namespace Microsoft.AspNetCore.Authentication.Google
/// <summary>
/// Provides the <see cref="AuthenticationHandler{T}"/> object for processing authentication-related requests.
/// </summary>
/// <returns>An <see cref="AuthenticationHandler{T}"/> configured with the <see cref="GoogleOptions"/> supplied to the constructor.</returns>
/// <returns>
/// An <see cref="AuthenticationHandler{T}"/> configured with the <see cref="GoogleOptions"/>
/// supplied to the constructor.
/// </returns>
protected override AuthenticationHandler<GoogleOptions> CreateHandler()
{
return new GoogleHandler(Backchannel);