2017-09-23 10:08:18 +02:00
|
|
|
|
using System;
|
2017-09-14 19:29:12 +02:00
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
using Microsoft.Owin;
|
|
|
|
|
|
using Microsoft.Owin.Security;
|
|
|
|
|
|
using Microsoft.Owin.Security.Infrastructure;
|
|
|
|
|
|
using Owin;
|
|
|
|
|
|
using Umbraco.Core.Security;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Umbraco.Tests.TestHelpers.ControllerTesting
|
|
|
|
|
|
{
|
|
|
|
|
|
public class AuthenticateEverythingMiddleware : AuthenticationMiddleware<AuthenticationOptions>
|
|
|
|
|
|
{
|
|
|
|
|
|
public AuthenticateEverythingMiddleware(OwinMiddleware next, IAppBuilder app, AuthenticationOptions options)
|
|
|
|
|
|
: base(next, options)
|
|
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected override AuthenticationHandler<AuthenticationOptions> CreateHandler()
|
|
|
|
|
|
{
|
|
|
|
|
|
return new AuthenticateEverythingHandler();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public class AuthenticateEverythingHandler : AuthenticationHandler<AuthenticationOptions>
|
|
|
|
|
|
{
|
|
|
|
|
|
protected override Task<AuthenticationTicket> AuthenticateCoreAsync()
|
|
|
|
|
|
{
|
2018-03-27 17:59:53 +02:00
|
|
|
|
var sessionId = Guid.NewGuid().ToString();
|
2017-09-14 19:29:12 +02:00
|
|
|
|
var identity = new UmbracoBackOfficeIdentity(
|
2018-04-05 23:10:51 +10:00
|
|
|
|
-1, "admin", "Admin", null, null, "en-US", sessionId, sessionId, new[] { "content", "media", "members" }, new[] { "admin" });
|
2017-09-14 19:29:12 +02:00
|
|
|
|
|
|
|
|
|
|
return Task.FromResult(new AuthenticationTicket(identity,
|
|
|
|
|
|
new AuthenticationProperties()
|
|
|
|
|
|
{
|
|
|
|
|
|
ExpiresUtc = DateTime.Now.AddDays(1)
|
|
|
|
|
|
}));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public class AuthenticateEverythingAuthenticationOptions : AuthenticationOptions
|
|
|
|
|
|
{
|
|
|
|
|
|
public AuthenticateEverythingAuthenticationOptions()
|
|
|
|
|
|
: base("AuthenticateEverything")
|
|
|
|
|
|
{
|
|
|
|
|
|
AuthenticationMode = AuthenticationMode.Active;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2017-09-23 10:08:18 +02:00
|
|
|
|
}
|