Skip to content

Instantly share code, notes, and snippets.

View explorer14's full-sized avatar

Aman Agrawal explorer14

View GitHub Profile
<rewrite>
<globalRules>
<rule name="ReverseProxyRule1" enabled="false">
<match url="^About" />
<action type="Rewrite" url="http://localhost:8021/Home/About" />
<conditions>
<add input="{SERVER_PORT}" pattern="88" />
</conditions>
</rule>
<rule name="ReverseProxyRule2" enabled="true" stopProcessing="true">
<rewrite>
<outboundRules>
<rule name="AnchorFixer" preCondition="IsHTML"
enabled="true" stopProcessing="true">
<match filterByTags="A" pattern="^/Home/(.*)" />
<action type="Rewrite" value="/{R:1}" />
</rule>
<rule name="LinkNScriptFixer" preCondition="IsHTML"
enabled="true" stopProcessing="true">
<match filterByTags="Link, Script" pattern="^/(css|js)/(.*)"
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
// ...other middleware
app.UseAuthentication();
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
public void ConfigureServices(IServiceCollection services)
{
services.AddAuthentication(options =>
{
// these must be set other ASP.NET Core will throw exception that no
// default authentication scheme or default challenge scheme is set.
options.DefaultAuthenticateScheme =
CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultChallengeScheme =
CookieAuthenticationDefaults.AuthenticationScheme;
public class HomeController : Controller
{
[Authorize]
public IActionResult About()
{
ViewData["Message"] = "Your application description page.";
return View();
}
}
[AllowAnonymous]
[HttpPost]
[ValidateAntiForgeryToken]
public async Task Login(UserCredentials userCredentials,
string returnUrl = null)
{
// I will fill this in a bit...
}
public interface IJwtTokenGenerator
{
TokenWithClaimsPrincipal GenerateAccessTokenWithClaimsPrincipal(string userName,
IEnumerable userClaims);
string GenerateAccessToken(string userName,
IEnumerable userClaims);
}
public class TokenWithClaimsPrincipal
{
public string AccessToken { get; internal set; }
public ClaimsPrincipal ClaimsPrincipal { get; internal set; }
public AuthenticationProperties AuthProperties { get; internal set; }
}
public IHostingEnvironment Environment {get; set;}
public void ConfigureServices(IServiceCollection services)
{
var signingKey = new SymmetricSecurityKey(
Encoding.ASCII.GetBytes(
Configuration["Token:SigningKey"]);
var validationParams = new TokenValidationParameters()
{
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public async Task Login(UserCredentials userCredentials,
string returnUrl = null)
{
ViewBag.returnUrl = returnUrl;
var returnTo = "/Account/Login";
// Replace this with your custom authentication logic