Skip to content

Instantly share code, notes, and snippets.

@kellypleahy
Created April 26, 2018 04:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kellypleahy/3fc3b2dfcc6b2afd6858a6aa0ad27030 to your computer and use it in GitHub Desktop.
Save kellypleahy/3fc3b2dfcc6b2afd6858a6aa0ad27030 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.IdentityModel.Tokens.Jwt;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.ApplicationInsights.DependencyCollector;
using Microsoft.ApplicationInsights.Extensibility;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc.Authorization;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.IdentityModel.Tokens;
using Newtonsoft.Json.Serialization;
namespace gicalcapi
{
public class Startup
{
...
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc(x =>
{
if (apiConfiguration.AuthorizationEnabled)
{
var policy = new AuthorizationPolicyBuilder()
.RequireAuthenticatedUser()
.Build();
x.Filters.Add(new AuthorizeFilter(policy));
}
});
}
...
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment