asp.net-identity

MVC 5 Role Based Authentication

余生长醉 提交于 2019-12-09 07:05:23
问题 I am trying to lock down our "admin" page to only admins using Asp.net Identity (we are building in MVC5). I can get [Authorize(Users="admin")] to work but can not get [Authorize(Roles="Admin")] to work. I have created the role in the dbo.AspNetRoles table and then associated the account in the AspNetUserRoles by pairing the user GUID to the ID in the aspnetroles table. I have seen in previous editions of MVC you have had to get into web.config to add some lines. Can anyone help point me in

Asp.net mvc identity SecurityStamp signout everywhere

时光怂恿深爱的人放手 提交于 2019-12-09 06:07:18
问题 What I want to do is to limit a user ID to only being able to log in to one device at a time. For example, user ID "abc" logs in to their computer. User ID "abc" now tries to log in from their phone. What I want to happen is to kill the session on their computer. I'm using Asp.net mvc identity membership and using SecurityStamp for this purpose. This is my code in Account/Login action: [HttpPost] [AllowAnonymous] [ValidateAntiForgeryToken] public async Task<ActionResult> Login(LoginViewModel

HttpContext.GetOwinContext().GetUserManager<AppRoleManager>() return null

只谈情不闲聊 提交于 2019-12-09 04:38:44
问题 I've used ASP.NET Identity 2 for creating role but the result of HttpContext.GetOwinContext().GetUserManager<AppRoleManager>() was null. Then I couldn't create the role. How can I solve this problem? public class MVCController : Controller { public MVCController() { } public AppRoleManager RoleManager // returns null ?! { get { return HttpContext.GetOwinContext().GetUserManager<AppRoleManager>(); } } public User CurrentUser { get { string currentUserId = User.Identity.GetUserId(); User

Identity Server 4 (2.0) not reading Asp.Net Core Identity cookies

梦想与她 提交于 2019-12-09 04:22:27
I am trying to use Asp .Net Identity Core with Identity Server 4 . I can see in the logs (Ids) that the user is logged in properly. info: Xena.IdentityServer.Controllers.AccountController[0] User logged in. My login controller then sends the user over to my Manage controller. [Route("[controller]/[action]")] [Authorize] //[Authorize(AuthenticationSchemes = "Identity.Application")] public class ManageController : Controller { [HttpGet] public async Task<IActionResult> Index(ManageMessageId? message = null) { ..... } } The User never arrives as the login is then lost for some reason. info:

Adding custom claim not working in asp.net core identity

蹲街弑〆低调 提交于 2019-12-09 02:04:05
问题 I have created CustomClaimType to store user id : public static class CustomClaimTypes { public const string UserId = "UserId"; } When user login, I set it: var claims = new List<Claim>(); claims.Add(new Claim(ClaimTypes.Name, doc_session.ufname + " " + doc_session.ulname)); claims.Add(new Claim(CustomClaimTypes.UserId, doc_session.isci_id.Value.ToString())); ClaimsIdentity userIdentity = new ClaimsIdentity(claims,"Identity.Application"); ClaimsPrincipal principal = new ClaimsPrincipal

aspnet identity using guid as key

十年热恋 提交于 2019-12-09 00:55:34
问题 I am trying to use Guid's instead of strings for my primary key and have followed the following posts: How to change type of id in Microsoft.AspNet.Identity.EntityFramework.IdentityUser and How to change type of id in Microsoft.AspNet.Identity.EntityFramework.IdentityUser I updated to the latest prerelease packages of aspnet identity Microsoft ASP.NET Identity Core 2.0.0-beta1 Microsoft ASP.NET Identity EntityFramework 2.0.0-beta1 and edited my User to allow for Guid's instead of the default

ASP.NET Identity (with IdentityServer4) get external resource oauth access token

偶尔善良 提交于 2019-12-08 23:00:19
问题 I have been through the docs of identityServer4 and I have set it up to use Microsoft Office 365 as a login provider. When the user has logged in I want to make a button where he can allow my app to subscribe to his calendar events using the webhooks api of graph.microsoft.com The code in startup.cs app.UseMicrosoftAccountAuthentication(new MicrosoftAccountOptions { AuthenticationScheme = "Microsoft", DisplayName = "Microsoft", SignInScheme = IdentityServerConstants

ASP.Net Identity 2 login using password from SMS - not using two-factor authentication

假装没事ソ 提交于 2019-12-08 22:40:38
Following blog series by @Taiseer Joudeh ( http://bitoftech.net/2015/01/21/asp-net-identity-2-with-asp-net-web-api-2-accounts-management/ ) I've build simple WebApi with JWT authentication. I'm able to login and query my endpoint using token. I'm trying to change how my login mechanism works. Right now user must send his login and password to /oauth/token to get access token that will be send with every request to webapi. I'd like to be able to login user with password that will be send via SMS to phone number assigned to his account. It should require two requests to token endpoint path.

Specified key was too long; max key length is 767 bytes - ASPNet Identity MySQL

耗尽温柔 提交于 2019-12-08 19:44:26
I have created an MVC Application with Identity and MySQL. I have created my entities but when I come to creating the user table it fails with the error specified in the title. I have searched around and people have said that the UserName , Name and Email properties are too long. I've tired to set a max length on these columns like the below example but I haven't been able to get it to work. IdentityModel: [DbConfigurationType(typeof(MySql.Data.Entity.MySqlEFConfiguration))] public class ApplicationDbContext : IdentityDbContext<ApplicationUser> { public ApplicationDbContext() : base(

User.IsInRole return false

风流意气都作罢 提交于 2019-12-08 19:14:43
问题 I 'm using Identity 2 for authentication in mvc 5 web site. In my view i want check the role of the user : @if(User.IsInRole("Customers")) { @*do something*@ } but this always return false, I have already set <roleManager enabled="true" /> in the web config. any help please. 回答1: I just got it to work with my setup that is also using Identity Framework. I added a user to a role by using the following code: this.RoleManager.CreateAsync(new Role() {Name = "Customers"}); this.UserManager