Skip to content
This repository has been archived by the owner on Oct 19, 2022. It is now read-only.

Commit

Permalink
Merge pull request #23 from stormpath/4.0.0
Browse files Browse the repository at this point in the history
4.0.0-rc1
  • Loading branch information
nbarbettini authored Apr 21, 2017
2 parents a9e4ae0 + 8314e93 commit 098398b
Show file tree
Hide file tree
Showing 22 changed files with 296 additions and 274 deletions.
17 changes: 11 additions & 6 deletions Stormpath.AspNet.sln
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.25123.0
# Visual Studio 15
VisualStudioVersion = 15.0.26403.7
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{C9C891A0-8043-4EAF-9DF1-39ACD3EFA488}"
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Stormpath.AspNet", "src\Stormpath.AspNet\Stormpath.AspNet.xproj", "{869166A9-F474-46DB-B06B-FD9922674D38}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{1A140068-0DEB-471A-97E3-3AFBD0EB9FE1}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Stormpath.AspNet.TckHarness", "test\Stormpath.AspNet.TckHarness\Stormpath.AspNet.TckHarness.csproj", "{42CED7DE-0739-47EF-9089-1FA85347E124}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "docs", "docs", "{6D732EF3-2AFE-482D-9EE3-C88C8907D755}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Stormpath.AspNet", "src\Stormpath.AspNet\Stormpath.AspNet.csproj", "{869166A9-F474-46DB-B06B-FD9922674D38}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Stormpath.AspNet.TckHarness", "test\Stormpath.AspNet.TckHarness\Stormpath.AspNet.TckHarness.csproj", "{42CED7DE-0739-47EF-9089-1FA85347E124}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Stormpath.AspNet.DocExamples", "docs\Stormpath.AspNet.DocExamples\Stormpath.AspNet.DocExamples.csproj", "{DF2E96E0-169B-4F69-B92A-A9CC30CAE2C2}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{584D2977-BBEB-4508-B996-9164E06BA8BF}"
ProjectSection(SolutionItems) = preProject
build.cake = build.cake
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down
14 changes: 10 additions & 4 deletions build.cake
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,22 @@ Task("Restore")
Task("Build")
.Does(() =>
{
DotNetCoreBuild("./src/**/project.json", new DotNetCoreBuildSettings
var projects = GetFiles("./src/**/*.csproj");
Console.WriteLine("Building {0} projects", projects.Count());

foreach (var project in projects)
{
Configuration = configuration
});
DotNetCoreBuild(project.FullPath, new DotNetCoreBuildSettings
{
Configuration = configuration
});
}
});

Task("Pack")
.Does(() =>
{
var projects = GetFiles("./src/**/project.json");
var projects = GetFiles("./src/**/*.csproj");
Console.WriteLine("Packing {0} projects", projects.Count());

foreach (var project in projects)
Expand Down
6 changes: 3 additions & 3 deletions src/Stormpath.AspNet/AccountIdentityTransformer.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
using System.Collections.Generic;
using System.Security.Claims;
using Stormpath.SDK.Account;
using Stormpath.Owin.Abstractions;

namespace Stormpath.AspNet
{
public static class AccountIdentityTransformer
{
public static ClaimsPrincipal CreatePrincipal(IAccount account, string scheme)
public static ClaimsPrincipal CreatePrincipal(ICompatibleOktaAccount account, string scheme)
{
var identity = CreateIdentity(account, scheme);

Expand All @@ -15,7 +15,7 @@ public static ClaimsPrincipal CreatePrincipal(IAccount account, string scheme)
: new ClaimsPrincipal(identity);
}

public static ClaimsIdentity CreateIdentity(IAccount account, string scheme)
public static ClaimsIdentity CreateIdentity(ICompatibleOktaAccount account, string scheme)
{
if (account == null)
{
Expand Down
34 changes: 4 additions & 30 deletions src/Stormpath.AspNet/HttpRequestExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,47 +2,21 @@
using System.Web;
using Stormpath.Configuration.Abstractions.Immutable;
using Stormpath.Owin.Abstractions;
using Stormpath.SDK.Account;
using Stormpath.SDK.Application;
using Stormpath.SDK.Client;
using Stormpath.SDK.Sync;

namespace Stormpath.AspNet
{
public static class HttpRequestExtensions
{
public static IClient GetStormpathClient(this HttpRequestBase request)
=> request.GetOwinContext().Get<IClient>(OwinKeys.StormpathClient);
public static ICompatibleOktaAccount GetStormpathAccount(this HttpRequestBase request)
=> request.GetOwinContext().Get<ICompatibleOktaAccount>(OwinKeys.StormpathUser);

public static IClient GetStormpathClient(this HttpRequestMessage request)
=> request.GetOwinContext().Get<IClient>(OwinKeys.StormpathClient);

public static IAccount GetStormpathAccount(this HttpRequestBase request)
=> request.GetOwinContext().Get<IAccount>(OwinKeys.StormpathUser);

public static IAccount GetStormpathAccount(this HttpRequestMessage request)
=> request.GetOwinContext().Get<IAccount>(OwinKeys.StormpathUser);
public static ICompatibleOktaAccount GetStormpathAccount(this HttpRequestMessage request)
=> request.GetOwinContext().Get<ICompatibleOktaAccount>(OwinKeys.StormpathUser);

public static StormpathConfiguration GetStormpathConfiguration(this HttpRequestBase request)
=> request.GetOwinContext().Get<StormpathConfiguration>(OwinKeys.StormpathConfiguration);

public static StormpathConfiguration GetStormpathConfiguration(this HttpRequestMessage request)
=> request.GetOwinContext().Get<StormpathConfiguration>(OwinKeys.StormpathConfiguration);

public static IApplication GetStormpathApplication(this HttpRequestBase request)
{
var client = request.GetStormpathClient();
var configuration = request.GetStormpathConfiguration();

return client.GetApplication(configuration.Application.Href);
}

public static IApplication GetStormpathApplication(this HttpRequestMessage request)
{
var client = request.GetStormpathClient();
var configuration = request.GetStormpathConfiguration();

return client.GetApplication(configuration.Application.Href);
}
}
}
18 changes: 8 additions & 10 deletions src/Stormpath.AspNet/RazorViewRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using Microsoft.Extensions.Logging;
using Stormpath.Configuration.Abstractions.Immutable;
using Stormpath.Owin.Abstractions;
using Stormpath.Owin.Abstractions.Configuration;
using Stormpath.Owin.Middleware;
using Stormpath.SDK.Account;
using Stormpath.SDK.Client;
using Stormpath.SDK.Logging;

namespace Stormpath.AspNet
{
Expand All @@ -33,7 +32,7 @@ public Task<bool> RenderAsync(string name, object model, IOwinEnvironment contex
var httpContext = context.Request[HttpContextKey] as HttpContextWrapper;
if (httpContext == null)
{
_logger.Error($"Request did not include item '{HttpContextKey}'", nameof(RazorViewRenderer));
_logger.LogError($"Request did not include item '{HttpContextKey}'", nameof(RazorViewRenderer));
return Task.FromResult(false);
}

Expand Down Expand Up @@ -63,7 +62,7 @@ public Task<bool> RenderAsync(string name, object model, IOwinEnvironment contex
}
catch (Exception ex)
{
_logger.Error(ex, null, nameof(RazorViewRenderer));
_logger.LogError(1000, ex, null, nameof(RazorViewRenderer));
return Task.FromResult(false);
}
}
Expand All @@ -74,7 +73,7 @@ private static IView FindView(string path, object model, ControllerContext contr

if (viewEngineResult?.View == null)
{
logger.Trace($"Could not find Razor view '{path}'", nameof(RazorViewRenderer));
logger.LogTrace($"Could not find Razor view '{path}'", nameof(RazorViewRenderer));
return null;
}

Expand All @@ -87,12 +86,11 @@ private static IView FindView(string path, object model, ControllerContext contr
private static void GetUserIdentity(HttpContextBase httpContext, ILogger logger)
{
var owinContext = httpContext.GetOwinContext();
var client = owinContext.Get<IClient>(OwinKeys.StormpathClient);
var config = owinContext.Get<StormpathConfiguration>(OwinKeys.StormpathConfiguration);
var config = owinContext.Get<IntegrationConfiguration>(OwinKeys.StormpathConfiguration);
var scheme = owinContext.Get<string>(OwinKeys.StormpathUserScheme);
var account = owinContext.Get<IAccount>(OwinKeys.StormpathUser);
var account = owinContext.Get<ICompatibleOktaAccount>(OwinKeys.StormpathUser);

var handler = new RouteProtector(client, config, null, null, null, null, logger);
var handler = new RouteProtector(config, null, null, null, null, logger);
var isAuthenticatedRequest = handler.IsAuthenticated(scheme, scheme, account);

if (isAuthenticatedRequest)
Expand Down
37 changes: 37 additions & 0 deletions src/Stormpath.AspNet/Stormpath.AspNet.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Description>Stormpath middleware for ASP.NET 4.5+. Easily add authentication and authorization to ASP.NET applications.</Description>
<Copyright>(c) 2016 Stormpath, Inc.</Copyright>
<VersionPrefix>4.0.0-rc1</VersionPrefix>
<Authors>Nate Barbettini</Authors>
<TargetFramework>net451</TargetFramework>
<NoWarn>$(NoWarn);CS1591</NoWarn>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<AssemblyName>Stormpath.AspNet</AssemblyName>
<PackageId>Stormpath.AspNet</PackageId>
<PackageTags>stormpath;authentication;authorization</PackageTags>
<PackageIconUrl>https://raw.githubusercontent.com/stormpath/stormpath-sdk-dotnet/master/icon.png</PackageIconUrl>
<PackageProjectUrl>https://github.com/stormpath/stormpath-aspnet</PackageProjectUrl>
<PackageLicenseUrl>https://github.com/stormpath/stormpath-aspnet/blob/master/LICENSE</PackageLicenseUrl>
<RepositoryUrl>https://github.com/stormpath/stormpath-aspnet</RepositoryUrl>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNet.Mvc" Version="5.2.3" />
<PackageReference Include="Microsoft.AspNet.WebApi.Owin" Version="5.2.3" />
<PackageReference Include="Microsoft.Owin" Version="3.1.0" />
<PackageReference Include="Microsoft.Owin.Host.SystemWeb" Version="3.1.0" />
<PackageReference Include="Microsoft.Owin.Security" Version="3.1.0" />
<PackageReference Include="Stormpath.Owin.Middleware" Version="4.0.0-rc1" />
<PackageReference Include="Stormpath.Owin.Views.Precompiled" Version="1.0.0-beta1" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net451' ">
<Reference Include="System.Web" />
<Reference Include="System" />
<Reference Include="Microsoft.CSharp" />
</ItemGroup>

</Project>
18 changes: 0 additions & 18 deletions src/Stormpath.AspNet/Stormpath.AspNet.xproj

This file was deleted.

3 changes: 1 addition & 2 deletions src/Stormpath.AspNet/StormpathAppBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ public static IAppBuilder UseStormpath(this IAppBuilder app, StormpathMiddleware
Configuration = options?.Configuration,
ConfigurationFileRoot = AppDomain.CurrentDomain.BaseDirectory,
Logger = options?.Logger,
CacheProvider = options?.CacheProvider,
PostChangePasswordHandler = options?.PostChangePasswordHandler,
PostLoginHandler = options?.PostLoginHandler,
PostLogoutHandler = options?.PostLogoutHandler,
Expand All @@ -53,12 +52,12 @@ public static IAppBuilder UseStormpath(this IAppBuilder app, StormpathMiddleware
PreLogoutHandler = options?.PreLogoutHandler,
PreRegistrationHandler = options?.PreRegistrationHandler,
PreVerifyEmailHandler = options?.PreVerifyEmailHandler,
SendVerificationEmailHandler = options?.SendVerificationEmailHandler
});

app.Use(stormpathMiddleware);

app.Use<StormpathAuthenticationMiddleware>(
stormpathMiddleware.GetClient(),
new StormpathAuthenticationOptions() { AllowedAuthenticationSchemes = new[] { "Cookie", "Bearer" } },
stormpathMiddleware.Configuration,
options?.Logger);
Expand Down
24 changes: 10 additions & 14 deletions src/Stormpath.AspNet/StormpathAuthenticationHandler.cs
Original file line number Diff line number Diff line change
@@ -1,35 +1,32 @@
using System;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Microsoft.Owin;
using Microsoft.Owin.Security;
using Microsoft.Owin.Security.Infrastructure;
using Stormpath.Configuration.Abstractions.Immutable;
using Stormpath.Owin.Abstractions;
using Stormpath.Owin.Abstractions.Configuration;
using Stormpath.Owin.Middleware;
using Stormpath.SDK.Account;
using Stormpath.SDK.Client;
using Stormpath.SDK.Logging;

namespace Stormpath.AspNet
{
public sealed class StormpathAuthenticationHandler : AuthenticationHandler<StormpathAuthenticationOptions>
{
private readonly SDK.Logging.ILogger _stormpathLogger;
private readonly ILogger _logger;
private readonly RouteProtector _protector;

public StormpathAuthenticationHandler(
IClient client,
IntegrationConfiguration configuration
, SDK.Logging.ILogger stormpathLogger)
IntegrationConfiguration configuration,
ILogger logger)
{
_stormpathLogger = stormpathLogger;
_logger = logger;

_protector = CreateRouteProtector(client, configuration);
_protector = CreateRouteProtector(configuration);
}

private RouteProtector CreateRouteProtector(IClient client, IntegrationConfiguration configuration)
private RouteProtector CreateRouteProtector(IntegrationConfiguration configuration)
{
var deleteCookieAction = new Action<WebCookieConfiguration>(cookie =>
{
Expand All @@ -45,19 +42,18 @@ private RouteProtector CreateRouteProtector(IClient client, IntegrationConfigura
var redirectAction = new Action<string>(location => Response.Redirect(location));

return new RouteProtector(
client,
configuration,
deleteCookieAction,
setStatusCodeAction,
setHeaderAction,
redirectAction,
_stormpathLogger);
_logger);
}

protected override Task<AuthenticationTicket> AuthenticateCoreAsync()
{
var scheme = Context.Get<string>(OwinKeys.StormpathUserScheme);
var account = Context.Get<IAccount>(OwinKeys.StormpathUser);
var account = Context.Get<ICompatibleOktaAccount>(OwinKeys.StormpathUser);

if (Options.AllowedAuthenticationSchemes.Any(potentialScheme => _protector.IsAuthenticated(scheme, potentialScheme, account)))
{
Expand All @@ -66,7 +62,7 @@ protected override Task<AuthenticationTicket> AuthenticateCoreAsync()
return Task.FromResult(ticket);
}

_stormpathLogger.Trace("Request is not authenticated", source: nameof(StormpathAuthenticationHandler));
_logger.LogTrace("Request is not authenticated", nameof(StormpathAuthenticationHandler));
return Task.FromResult<AuthenticationTicket>(null);
}

Expand Down
Loading

0 comments on commit 098398b

Please sign in to comment.