Created
April 29, 2016 07:40
-
-
Save herecydev/b729403448943f3df5229767e4981c12 to your computer and use it in GitHub Desktop.
RedirectLoop
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
public class Startup | |
{ | |
public Startup(IHostingEnvironment env) | |
{ | |
var builder = new ConfigurationBuilder().AddJsonFile("appsettings.json"); | |
Configuration = builder.Build(); | |
} | |
public IConfigurationRoot Configuration { get; set; } | |
public void ConfigureServices(IServiceCollection services) | |
{ | |
services.AddAuthorization(options => | |
{ | |
options.AddPolicy("IsDeveloper", builder => | |
{ | |
builder.RequireAuthenticatedUser(); | |
builder.RequireClaim("FakeClaim", "NobodyWillHaveAClaimLikeThis"); | |
}); | |
}); | |
services.AddMvc(); | |
} | |
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) | |
{ | |
loggerFactory.AddConsole(); | |
app.UseCookieAuthentication(options => | |
{ | |
options.AutomaticAuthenticate = true; | |
options.AutomaticChallenge = true; | |
}); | |
app.UseOpenIdConnectAuthentication(options => | |
{ | |
options.Authority = Configuration.Get<string>("AzureAd:Authority"); | |
options.ClientId = Configuration.Get<string>("AzureAd:ClientId"); | |
options.AutomaticAuthenticate = true; | |
options.AutomaticChallenge = true; | |
options.SignInScheme = CookieAuthenticationDefaults.AuthenticationScheme; | |
}); | |
app.UseMvc(); | |
} | |
public static void Main(string[] args) => WebApplication.Run<Startup>(args); | |
} |
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
[Route("api/[controller]")] | |
[Authorize("IsDeveloper")] | |
public class ValuesController : Controller | |
{ | |
[HttpGet] | |
public IEnumerable<string> Get() | |
{ | |
return new string[] { "value1", "value2" }; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment