Skip to content
This repository was archived by the owner on Mar 23, 2022. It is now read-only.

Add aspnetcore support #127

Merged
merged 19 commits into from
Oct 3, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ TestResult.xml
[Rr]eleasePS/
dlldata.c

# DNX
project.lock.json
artifacts/

*_i.c
*_p.c
*_i.h
Expand Down
29 changes: 28 additions & 1 deletion Stuntman.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.24720.0
VisualStudioVersion = 14.0.25420.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Core", "src\Core\Core.csproj", "{A3951ED6-0AD3-424C-B5BC-8008C80EEA02}"
EndProject
Expand All @@ -19,6 +19,14 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UsageSample.BearerTokenTest
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UsageSample.ServerTester", "samples\UsageSample.ServerTester\UsageSample.ServerTester.csproj", "{EE3E17BB-74F9-4314-A529-5DE79B9E7D34}"
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Core.AspNetCore.Tests", "tests\Core.AspNetCore.Tests\Core.AspNetCore.Tests.xproj", "{162CDC91-8B1B-48AB-BD7E-A24014B039F6}"
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "UsageSample.AspNetCore", "samples\UsageSample.AspNetCore\UsageSample.AspNetCore.xproj", "{77130FF6-DFCC-4D30-B560-0E23A09A6726}"
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "UsageSampleMvc.AspNetCore", "samples\UsageSampleMvc.AspNetCore\UsageSampleMvc.AspNetCore.xproj", "{7BE101FC-EB16-43B4-A25B-9F590096F776}"
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "RimDev.Stuntman.Core.AspNetCore", "src\RimDev.Stuntman.Core.AspNetCore\RimDev.Stuntman.Core.AspNetCore.xproj", "{2822BCC5-31B2-45F3-A298-908643CA39BA}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -49,6 +57,22 @@ Global
{EE3E17BB-74F9-4314-A529-5DE79B9E7D34}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EE3E17BB-74F9-4314-A529-5DE79B9E7D34}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EE3E17BB-74F9-4314-A529-5DE79B9E7D34}.Release|Any CPU.Build.0 = Release|Any CPU
{162CDC91-8B1B-48AB-BD7E-A24014B039F6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{162CDC91-8B1B-48AB-BD7E-A24014B039F6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{162CDC91-8B1B-48AB-BD7E-A24014B039F6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{162CDC91-8B1B-48AB-BD7E-A24014B039F6}.Release|Any CPU.Build.0 = Release|Any CPU
{77130FF6-DFCC-4D30-B560-0E23A09A6726}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{77130FF6-DFCC-4D30-B560-0E23A09A6726}.Debug|Any CPU.Build.0 = Debug|Any CPU
{77130FF6-DFCC-4D30-B560-0E23A09A6726}.Release|Any CPU.ActiveCfg = Release|Any CPU
{77130FF6-DFCC-4D30-B560-0E23A09A6726}.Release|Any CPU.Build.0 = Release|Any CPU
{7BE101FC-EB16-43B4-A25B-9F590096F776}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7BE101FC-EB16-43B4-A25B-9F590096F776}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7BE101FC-EB16-43B4-A25B-9F590096F776}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7BE101FC-EB16-43B4-A25B-9F590096F776}.Release|Any CPU.Build.0 = Release|Any CPU
{2822BCC5-31B2-45F3-A298-908643CA39BA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2822BCC5-31B2-45F3-A298-908643CA39BA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2822BCC5-31B2-45F3-A298-908643CA39BA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2822BCC5-31B2-45F3-A298-908643CA39BA}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -59,5 +83,8 @@ Global
{0CB0CB75-7BF7-44BD-A003-E4176AFD4EBC} = {418B6F96-6578-4B18-823C-0FC7A712F0BE}
{CF8863AC-C37A-4E89-86FE-9B365818D9F2} = {418B6F96-6578-4B18-823C-0FC7A712F0BE}
{EE3E17BB-74F9-4314-A529-5DE79B9E7D34} = {418B6F96-6578-4B18-823C-0FC7A712F0BE}
{162CDC91-8B1B-48AB-BD7E-A24014B039F6} = {5243DBF7-7270-4460-9AC2-C343D653826E}
{77130FF6-DFCC-4D30-B560-0E23A09A6726} = {418B6F96-6578-4B18-823C-0FC7A712F0BE}
{7BE101FC-EB16-43B4-A25B-9F590096F776} = {418B6F96-6578-4B18-823C-0FC7A712F0BE}
EndGlobalSection
EndGlobal
12 changes: 12 additions & 0 deletions build.cmd
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ if not exist .nuget @mkdir .nuget

:Build

dotnet restore
if %ERRORLEVEL% neq 0 goto BuildFail

dotnet build .\**\project.json -c Release
if %ERRORLEVEL% neq 0 goto BuildFail

:: Find the most recent 32bit MSBuild.exe on the system. Also handle x86 operating systems, where %PROGRAMFILES(X86)%
:: is not defined. Always quote the %MSBUILD% value when setting the variable and never quote %MSBUILD% references.
set MSBUILD="%PROGRAMFILES(X86)%\MSBuild\14.0\Bin\MSBuild.exe"
Expand All @@ -25,6 +31,12 @@ if not exist %MSBUILD% @set MSBUILD="%PROGRAMFILES%\MSBuild\12.0\Bin\MSBuild.exe
if not exist %MSBUILD% @set MSBUILD="%SYSTEMROOT%\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe"

%MSBUILD% build\Build.msbuild /nologo /m /v:m /fl /flp:LogFile=msbuild.log;Verbosity=Detailed /nr:false %*
if %ERRORLEVEL% neq 0 goto BuildFail

dotnet test .\tests\Core.AspNetCore.Tests -c Release
if %ERRORLEVEL% neq 0 goto BuildFail

dotnet pack .\src\RimDev.Stuntman.Core.AspNetCore -c Release -o .\artifacts

if %ERRORLEVEL% neq 0 goto BuildFail
goto BuildSuccess
Expand Down
6 changes: 6 additions & 0 deletions global.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"projects": [ "src", "tests", "samples" ],
"sdk": {
"version": "1.0.0-preview2-003133"
}
}
24 changes: 24 additions & 0 deletions samples/UsageSample.AspNetCore/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Hosting;

namespace UsageSample.AspNetCore
{
public class Program
{
public static void Main(string[] args)
{
var host = new WebHostBuilder()
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.UseStartup<Startup>()
.Build();

host.Run();
}
}
}
4 changes: 4 additions & 0 deletions samples/UsageSample.AspNetCore/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
using System.Reflection;

[assembly: AssemblyTitle("RimDev.Stuntman.UsageSample.AspNetCore")]

27 changes: 27 additions & 0 deletions samples/UsageSample.AspNetCore/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:60234/",
"sslPort": 0
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"UsageSample.AspNetCore": {
"commandName": "Project",
"launchBrowser": true,
"launchUrl": "http://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
164 changes: 164 additions & 0 deletions samples/UsageSample.AspNetCore/Startup.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using RimDev.Stuntman.Core;

namespace UsageSample.AspNetCore
{
public class Startup
{
public IHostingEnvironment Environment { get; set; }

public Startup(IHostingEnvironment env)
{
Environment = env;
}

// This method gets called by the runtime. Use this method to add services to the container.
// For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services)
{
services.AddAuthentication();

services.AddSingleton(
new StuntmanOptions()
.EnableServer()
.AddUser(new StuntmanUser("user-1", "User 1")
.SetAccessToken("user-1-token")
.SetDescription("This is User 1.")
.AddClaim("given_name", "John")
.AddClaim("family_name", "Doe"))
.AddUser(new StuntmanUser("user-2", "User 2")
.AddClaim("given_name", "Jane")
.AddClaim("family_name", "Doe"))
.AddUser(new StuntmanUser("user-3", "User 3")
.AddClaim("given_name", "Sam")
.AddClaim("family_name", "Smith"))
.AddUsersFromJson(
"https://raw.githubusercontent.com/ritterim/stuntman/master/samples/UsageSample/test-users-1.json")
.AddUsersFromJson(Path.Combine(Environment.ContentRootPath, "test-users-2.json")));

}

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{

var stuntmanOptions = app.ApplicationServices.GetService<StuntmanOptions>();

if (env.IsDevelopment())
{
app.UseStuntman(stuntmanOptions);
}

app.Map("/secure", secure =>
{
AuthenticateAllRequests(secure, "StuntmanAuthentication");

secure.Run(async context =>
{
var userName = context.User.Identity.Name;

if (string.IsNullOrEmpty(userName))
userName = "Anonymous / Unknown";

context.Response.ContentType = "text/html";
await context.Response.WriteAsync(
$"Hello, {userName}. This is the /secure endpoint.");

if (env.IsDevelopment())
{
await context.Response.WriteAsync(
stuntmanOptions.UserPicker(context.User));
}
});
});

app.Map("/secure-json", secure =>
{
AuthenticateAllRequests(secure, "StuntmanAuthentication");

secure.Run(async context =>
{
var userName = context.User.Identity.Name;

if (string.IsNullOrEmpty(userName))
userName = "Anonymous / Unknown";

context.Response.ContentType = "application/json";
await context.Response.WriteAsync(
$@"{{""message"":""Hello, {userName}. This is the /secure-json endpoint.""}}");

});
});

app.Map("/logout", logout =>
{
logout.Run(async context =>
{
await context.Authentication.SignOutAsync("StuntmanAuthentication");
});
});

app.Map("", nonSecure =>
{
nonSecure.Run(async context =>
{
var userName = context.User.Identity.Name;

if (string.IsNullOrEmpty(userName))
userName = "Anonymous / Unknown";

context.Response.ContentType = "text/html";

await context.Response.WriteAsync(
@"<!DOCTYPE html>
<html>
<head>
<meta charset=""utf-8"">
<title>Stuntman - UsageSample</title>
</head>
<body>");

await context.Response.WriteAsync(
$"Hello, {userName}.");

if (env.IsDevelopment())
{
await context.Response.WriteAsync(
stuntmanOptions.UserPicker(context.User));
}

await context.Response.WriteAsync(
@"</body>
</html>");
});
});
}

// http://stackoverflow.com/a/26265757
private static void AuthenticateAllRequests(IApplicationBuilder app, string authenticationType)
{
app.Use(async (context, continuation) =>
{
if (context.User != null &&
context.User.Identity != null &&
context.User.Identity.IsAuthenticated)
{
await continuation();
}
else
{
await context.Authentication.ChallengeAsync(authenticationType);
}
});
}
}
}
25 changes: 25 additions & 0 deletions samples/UsageSample.AspNetCore/UsageSample.AspNetCore.xproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>

<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.Props" Condition="'$(VSToolsPath)' != ''" />
<PropertyGroup Label="Globals">
<ProjectGuid>77130ff6-dfcc-4d30-b560-0e23a09a6726</ProjectGuid>
<RootNamespace>UsageSample.AspNetCore</RootNamespace>
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">.\obj</BaseIntermediateOutputPath>
<OutputPath Condition="'$(OutputPath)'=='' ">.\bin\</OutputPath>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
</PropertyGroup>

<PropertyGroup>
<SchemaVersion>2.0</SchemaVersion>
</PropertyGroup>
<ItemGroup>
<DnxInvisibleContent Include="bower.json" />
<DnxInvisibleContent Include=".bowerrc" />
</ItemGroup>
<Import Project="$(VSToolsPath)\DotNet.Web\Microsoft.DotNet.Web.targets" Condition="'$(VSToolsPath)' != ''" />
</Project>
Loading