This repository has been archived by the owner on Jan 24, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduced new route declaration syntax
- Loading branch information
1 parent
2c07700
commit b490c6b
Showing
104 changed files
with
2,281 additions
and
2,348 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
namespace Nancy.Demo.Authentication.Basic | ||
{ | ||
public class MainModule : LegacyNancyModule | ||
public class MainModule : NancyModule | ||
{ | ||
public MainModule() | ||
{ | ||
Get["/"] = _ => "<a href='/secure'>Enter</a>"; | ||
Get("/", args => "<a href='/secure'>Enter</a>"); | ||
} | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
31 changes: 16 additions & 15 deletions
31
samples/Nancy.Demo.Authentication.Stateless/AuthModule.cs
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,28 @@ | ||
namespace Nancy.Demo.Authentication.Stateless | ||
{ | ||
public class AuthModule : LegacyNancyModule | ||
public class AuthModule : NancyModule | ||
{ | ||
public AuthModule() : base("/auth/") | ||
{ | ||
//the Post["/login"] method is used mainly to fetch the api key for subsequent calls | ||
Post["/"] = x => | ||
{ | ||
string apiKey = UserDatabase.ValidateUser((string) this.Request.Form.Username, | ||
(string) this.Request.Form.Password); | ||
Post("/", args => | ||
{ | ||
var apiKey = UserDatabase.ValidateUser( | ||
(string) this.Request.Form.Username, | ||
(string) this.Request.Form.Password); | ||
return string.IsNullOrEmpty(apiKey) | ||
? new Response {StatusCode = HttpStatusCode.Unauthorized} | ||
: this.Response.AsJson(new {ApiKey = apiKey}); | ||
}; | ||
return string.IsNullOrEmpty(apiKey) | ||
? new Response {StatusCode = HttpStatusCode.Unauthorized} | ||
: this.Response.AsJson(new {ApiKey = apiKey}); | ||
}); | ||
|
||
//do something to destroy the api key, maybe? | ||
Delete["/"] = x => | ||
{ | ||
var apiKey = (string) this.Request.Form.ApiKey; | ||
UserDatabase.RemoveApiKey(apiKey); | ||
return new Response {StatusCode = HttpStatusCode.OK}; | ||
}; | ||
Delete("/", args => | ||
{ | ||
var apiKey = (string) this.Request.Form.ApiKey; | ||
UserDatabase.RemoveApiKey(apiKey); | ||
return new Response {StatusCode = HttpStatusCode.OK}; | ||
}); | ||
} | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,15 @@ | ||
namespace Nancy.Demo.Authentication.Stateless | ||
{ | ||
public class RootModule : LegacyNancyModule | ||
public class RootModule : NancyModule | ||
{ | ||
public RootModule() | ||
{ | ||
Get["/"] = _ => this.Response.AsText("This is a REST API. It is in another VS project to " + | ||
Get("/", args => this.Response.AsText("This is a REST API. It is in another VS project to " + | ||
"demonstrate how a common REST API might behave when " + | ||
"accessing it from another website or application. To " + | ||
"see how a website can access this API, run the " + | ||
"Nancy.Demo.Authentication.Stateless.Website project " + | ||
"(in the same Nancy solution)."); | ||
"(in the same Nancy solution).")); | ||
} | ||
} | ||
} |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,23 @@ | ||
namespace Nancy.Demo.Authentication | ||
{ | ||
using System.Security.Claims; | ||
|
||
using Nancy.Demo.Authentication.Models; | ||
using Nancy.Security; | ||
|
||
/// <summary> | ||
/// A module that only people with SuperSecure clearance are allowed to access | ||
/// </summary> | ||
public class AnotherVerySecureModule : LegacyNancyModule | ||
public class AnotherVerySecureModule : NancyModule | ||
{ | ||
public AnotherVerySecureModule() : base("/superSecure") | ||
{ | ||
this.RequiresClaims(c => c.Type == ClaimTypes.Role && c.Value == "SuperSecure"); | ||
|
||
Get["/"] = x => | ||
Get("/", args => | ||
{ | ||
var model = new UserModel(this.Context.CurrentUser.Identity.Name); | ||
return View["superSecure.cshtml", model]; | ||
}; | ||
}); | ||
} | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,16 @@ | ||
namespace Nancy.Demo.Authentication | ||
{ | ||
public class MainModule : LegacyNancyModule | ||
public class MainModule : NancyModule | ||
{ | ||
public MainModule() | ||
{ | ||
Get["/"] = x => { | ||
Get("/", args => { | ||
return View["Index.cshtml"]; | ||
}; | ||
}); | ||
|
||
Get["/login"] = x => { | ||
Get("/login", args => { | ||
return View["Login.cshtml", this.Request.Query.returnUrl]; | ||
}; | ||
}); | ||
} | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,25 @@ | ||
namespace Nancy.Demo.Caching | ||
{ | ||
using System; | ||
|
||
using Nancy.Demo.Caching.CachingExtensions; | ||
|
||
public class MainModule : LegacyNancyModule | ||
public class MainModule : NancyModule | ||
{ | ||
public MainModule() | ||
{ | ||
Get["/"] = x => { | ||
Get("/", args => { | ||
return View["Index.cshtml", DateTime.Now.ToString()]; | ||
}; | ||
}); | ||
|
||
Get["/cached"] = x => { | ||
Get("/cached", args => { | ||
this.Context.EnableOutputCache(30); | ||
return View["Payload.cshtml", DateTime.Now.ToString()]; | ||
}; | ||
}); | ||
|
||
Get["/uncached"] = x => { | ||
Get("/uncached", args => { | ||
this.Context.DisableOutputCache(); | ||
return View["Payload.cshtml", DateTime.Now.ToString()]; | ||
}; | ||
}); | ||
} | ||
} | ||
} |
Oops, something went wrong.