Skip to content

Instantly share code, notes, and snippets.

View juanvan's full-sized avatar
🏠
Working from home

juanvan

🏠
Working from home
View GitHub Profile
private async Task<dynamic> GenerateToken(string username)
{
var user = await _userManager.FindByEmailAsync(username);
var roles = from ur in _context.UserRoles
join r in _context.Roles on ur.RoleId equals r.Id
where ur.UserId == user.Id
select new { ur.UserId, ur.RoleId, r.Name };
var claims = new List<Claim>
{
services.AddAuthentication(options =>
{
options.DefaultAuthenticateScheme = "JwtBearer";
//options.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme;
//options.DefaultSignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = "JwtBearer";
})
.AddJwtBearer("JwtBearer", jwtBearerOptions =>
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
@juanvan
juanvan / .cs
Created May 14, 2019 19:10
BaseIdentityExample
BaseIdentityController : Controller
{
public ApplicationSignInManager _signInManager;
public ApplicationUserManager _userManager;
public BaseIdentityController()
{
}
public BaseIdentityController(ApplicationUserManager userManager, ApplicationSignInManager signInManager)
{