This file contains hidden or 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
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> | |
{ |
This file contains hidden or 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
services.AddAuthentication(options => | |
{ | |
options.DefaultAuthenticateScheme = "JwtBearer"; | |
//options.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme; | |
//options.DefaultSignInScheme = CookieAuthenticationDefaults.AuthenticationScheme; | |
options.DefaultChallengeScheme = "JwtBearer"; | |
}) | |
.AddJwtBearer("JwtBearer", jwtBearerOptions => |
This file contains hidden or 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(IConfiguration configuration) | |
{ | |
Configuration = configuration; | |
} | |
public IConfiguration Configuration { get; } | |
// This method gets called by the runtime. Use this method to add services to the container. |
This file contains hidden or 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
BaseIdentityController : Controller | |
{ | |
public ApplicationSignInManager _signInManager; | |
public ApplicationUserManager _userManager; | |
public BaseIdentityController() | |
{ | |
} | |
public BaseIdentityController(ApplicationUserManager userManager, ApplicationSignInManager signInManager) | |
{ |