commentaire nul
parent
cac49facaa
commit
46f5c107b8
@ -0,0 +1,80 @@
|
|||||||
|
// 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>
|
||||||
|
public class YavscOAuthMiddleware : OAuthMiddleware<YavscOAuthOptions>
|
||||||
|
{
|
||||||
|
private RequestDelegate _next;
|
||||||
|
private ILogger _logger;
|
||||||
|
private SharedAuthenticationOptions _sharedOptions;
|
||||||
|
|
||||||
|
/// <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 YavscOAuthMiddleware(
|
||||||
|
RequestDelegate next,
|
||||||
|
IDataProtectionProvider dataProtectionProvider,
|
||||||
|
ILoggerFactory loggerFactory,
|
||||||
|
UrlEncoder encoder,
|
||||||
|
IOptions<SharedAuthenticationOptions> sharedOptions,
|
||||||
|
YavscOAuthOptions options)
|
||||||
|
: 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<YavscOAuthMiddleware>();
|
||||||
|
|
||||||
|
if (encoder == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(encoder));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sharedOptions == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(sharedOptions));
|
||||||
|
}
|
||||||
|
_sharedOptions = sharedOptions.Value;
|
||||||
|
|
||||||
|
if (options == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(options));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override AuthenticationHandler<YavscOAuthOptions> CreateHandler()
|
||||||
|
{
|
||||||
|
return new YavscOAuthHandler(Backchannel,_sharedOptions,_logger);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,24 @@
|
|||||||
|
|
||||||
|
|
||||||
|
using Microsoft.AspNet.Authentication.OAuth;
|
||||||
|
using Microsoft.AspNet.Http;
|
||||||
|
|
||||||
|
public class YavscOAuthOptions : OAuthOptions {
|
||||||
|
public YavscOAuthOptions()
|
||||||
|
{
|
||||||
|
AuthenticationScheme = "yavsc";
|
||||||
|
DisplayName = AuthenticationScheme;
|
||||||
|
CallbackPath = new PathString("/signin-yavsc");
|
||||||
|
AuthorizationEndpoint = "http://dev.pschneider.fr/connect/authorize";
|
||||||
|
TokenEndpoint = "http://dev.pschneider.fr/api/token/get";
|
||||||
|
UserInformationEndpoint = "http://dev.pschneider.fr/api/userinfo";
|
||||||
|
Scope.Add("openid");
|
||||||
|
Scope.Add("profile");
|
||||||
|
Scope.Add("email");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// access_type. Set to 'offline' to request a refresh token.
|
||||||
|
/// </summary>
|
||||||
|
public string AccessType { get; set; }
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue