Last active
November 8, 2018 17:58
-
-
Save haukurk/52c762bc763784b69ad8999157c9e3eb to your computer and use it in GitHub Desktop.
.NET Core NancyFx with IdentityServer4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM microsoft/dotnet:1.1.1-sdk | |
COPY ./NancyAPI.csproj /app/ | |
WORKDIR /app/ | |
RUN dotnet restore | |
ADD ./ /app/ | |
RUN dotnet publish -c Debug | |
EXPOSE 5000 | |
ENTRYPOINT ["dotnet", "run"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Nancy; | |
using Nancy.Security; | |
using System; | |
using System.Linq; | |
using System.Security.Claims; | |
namespace NancyAPI.Module | |
{ | |
public class HomeModule : NancyModule | |
{ | |
public HomeModule() : base("/") | |
{ | |
this.RequiresAuthentication(); | |
Get("/", args => "Hello World. This is pretty cool!"); | |
Get("/test/{name}", args => new Person() { Name = args.name }); | |
Get("/claims", args => | |
{ | |
this.RequiresClaims(claim => claim.Type == "role" && claim.Value == "test1"); | |
return "Congratz, You have role test1"; | |
}); | |
} | |
public class Person | |
{ | |
public string Name { get; set; } | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.IO; | |
using Microsoft.AspNetCore.Builder; | |
using Microsoft.AspNetCore.Hosting; | |
namespace NancyAPI | |
{ | |
public class Program | |
{ | |
public static void Main(string[] args) | |
{ | |
var host = new WebHostBuilder() | |
.UseContentRoot(Directory.GetCurrentDirectory()) | |
.UseKestrel() | |
.UseStartup<Startup>() | |
.UseUrls("http://0.0.0.0:5009") | |
.Build(); | |
host.Run(); | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Microsoft.AspNetCore.Authentication; | |
using Microsoft.AspNetCore.Builder; | |
using Microsoft.Extensions.Configuration; | |
using Microsoft.Extensions.DependencyInjection; | |
using Nancy.Bootstrapper; | |
using Nancy.Owin; | |
using Nancy.TinyIoc; | |
namespace NancyAPI | |
{ | |
public class Startup | |
{ | |
public void ConfigureServices(IServiceCollection services) | |
{ | |
services.AddWebEncoders(); | |
} | |
public void Configure(IApplicationBuilder app) | |
{ | |
app.UseIdentityServerAuthentication(new IdentityServerAuthenticationOptions | |
{ | |
Authority = "https://identity.hauxi.is", | |
RequireHttpsMetadata = true, | |
ApiName = "nancyapi" | |
}); | |
app.UseOwin(x => x.UseNancy()); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment