81 lines
2.7 KiB
C#
81 lines
2.7 KiB
C#
8 years ago
|
// Copyright (c) .NET Foundation. All rights reserved.
|
||
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||
|
|
||
|
using System;
|
||
|
using Microsoft.AspNet.Authentication;
|
||
|
using Microsoft.AspNet.Authentication.OAuth;
|
||
|
using Microsoft.AspNet.Builder;
|
||
|
using Microsoft.AspNet.DataProtection;
|
||
|
using Microsoft.Extensions.Logging;
|
||
|
using Microsoft.Extensions.OptionsModel;
|
||
|
using Microsoft.Extensions.WebEncoders;
|
||
|
namespace Yavsc.Auth
|
||
|
{
|
||
|
/// <summary>
|
||
|
/// An ASP.NET Core middleware for authenticating users using Google OAuth 2.0.
|
||
|
/// </summary>
|
||
8 years ago
|
public class GoogleMiddleware : OAuthMiddleware<YavscGoogleOptions>
|
||
8 years ago
|
{
|
||
|
private RequestDelegate _next;
|
||
|
private ILogger _logger;
|
||
|
|
||
|
/// <summary>
|
||
|
/// Initializes a new <see cref="GoogleMiddleware"/>.
|
||
|
/// </summary>
|
||
|
/// <param name="next">The next middleware in the HTTP pipeline to invoke.</param>
|
||
|
/// <param name="dataProtectionProvider"></param>
|
||
|
/// <param name="loggerFactory"></param>
|
||
|
/// <param name="encoder"></param>
|
||
|
/// <param name="sharedOptions"></param>
|
||
|
/// <param name="options">Configuration options for the middleware.</param>
|
||
|
public GoogleMiddleware(
|
||
|
RequestDelegate next,
|
||
|
IDataProtectionProvider dataProtectionProvider,
|
||
|
ILoggerFactory loggerFactory,
|
||
|
UrlEncoder encoder,
|
||
|
IOptions<SharedAuthenticationOptions> sharedOptions,
|
||
8 years ago
|
YavscGoogleOptions options)
|
||
8 years ago
|
: base(next, dataProtectionProvider, loggerFactory, encoder, sharedOptions, options)
|
||
|
{
|
||
|
if (next == null)
|
||
|
{
|
||
|
throw new ArgumentNullException(nameof(next));
|
||
|
}
|
||
|
_next = next;
|
||
|
|
||
|
if (dataProtectionProvider == null)
|
||
|
{
|
||
|
throw new ArgumentNullException(nameof(dataProtectionProvider));
|
||
|
}
|
||
|
|
||
|
if (loggerFactory == null)
|
||
|
{
|
||
|
throw new ArgumentNullException(nameof(loggerFactory));
|
||
|
}
|
||
|
_logger = loggerFactory.CreateLogger<GoogleMiddleware>();
|
||
|
|
||
|
if (encoder == null)
|
||
|
{
|
||
|
throw new ArgumentNullException(nameof(encoder));
|
||
|
}
|
||
|
|
||
|
if (sharedOptions == null)
|
||
|
{
|
||
|
throw new ArgumentNullException(nameof(sharedOptions));
|
||
|
}
|
||
|
|
||
|
if (options == null)
|
||
|
{
|
||
|
throw new ArgumentNullException(nameof(options));
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
8 years ago
|
protected override AuthenticationHandler<YavscGoogleOptions> CreateHandler()
|
||
8 years ago
|
{
|
||
|
return new GoogleHandler(Backchannel,_logger);
|
||
|
}
|
||
|
|
||
|
}
|
||
|
}
|