asp.net-identity

Asp.Net Identity - Updating Claims After Login

杀马特。学长 韩版系。学妹 提交于 2019-12-08 17:43:21
问题 I am using asp.net identity (WebApi 2, MVC 5, not .net core) to add claims to my user's identity when she logs in from our singe page application. This looks like this (I have stripped out the checks for invalid names, locked accounts, etc) public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context) { var userManager = context.OwinContext.GetUserManager<CompWalkUserManager>(); var user = await userManager.FindByNameAsync(context.UserName); var

User.Identity.IsAuthenticated always false after PasswordSignInAsync gives success

落花浮王杯 提交于 2019-12-08 16:56:49
问题 I've got a standard MVC project, with the UserManager and SignInManager objects and an AccountController, with the pre-created login and register type functionality. I can register new users to my AspNetUsers table, but when I login I call:- var result = await SignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, shouldLockout: false); The data is coming through from the form correctly, and the result is Success, which I expected. I then tried the following

Is there any way I can mock a Claims Principal in my ASP.NET MVC web application?

非 Y 不嫁゛ 提交于 2019-12-08 16:38:16
问题 I've got some ASP.NET MVC controller code that checks if a user is authenticated and if so, it checks to see if it has a specific claim. Works fine. I've got some unit tests and I need to mock out an IPrincipal (which is easy to do) ... but I'm not sure how to check for the claims! I usually do something like public static ClaimsPrincipal ClaimsPrincipal(this Controller controller) { return controller.User as ClaimsPrincipal; } and some controller code ... this.ClaimsPrincipal().HasClaim(x =>

asp.net identity userName is unique?

狂风中的少年 提交于 2019-12-08 15:27:07
问题 I was reading about user Identity in Microsoft and trying to apply them in my MVC5 app. Up to my knowledge the Id is the key, while the userName is not key and the definition says that it can be null, so I was asking myself... why in the MVC5 project template, when you enter an already existing userName you will receive an Error message ?? I tried to reach to the userName validation but I couldn't. Here is the database definition: CREATE TABLE [dbo].[AspNetUsers] ( [Id] NVARCHAR (128) NOT

MVC AuthenticationManager.SignOut() is not signing out

蹲街弑〆低调 提交于 2019-12-08 15:21:03
问题 My project is based on the MVC 5 project template from Visual Studio 2013 (individual user account option). I have been relying on the default Sign In and Sign Out method for my users. But I'm not sure what I did, at some point, users cannot sign out anymore, however they can sign in as another user. This is the default Logoff method of Account Controller [HttpPost] [ValidateAntiForgeryToken] public ActionResult LogOff() { AuthenticationManager.SignOut(); return RedirectToAction("Index",

How can I delete an asp.net identity 2.2.1 user in MVC5?

牧云@^-^@ 提交于 2019-12-08 13:59:32
问题 I am using asp.net identity 2.2.1 and I want to delete a user when he/she tries to hit a specific action method in one of none account controllers. Being into many SO question each of them points to a version dependent solution and frankly I couldn't find a to the point answer. Why there is no plain and simple documentation on deleting an identity user and most importantly why this feature is not part of the identity it self? Please note that I am using individual user accounts for external

SQL Server Express connection to .mdf file

只谈情不闲聊 提交于 2019-12-08 11:54:22
问题 Two-Part Question. I have created an ASP.NET MVC 5 application using VS 2015 Update 3. I am quite a ways along with the project on my local machine. Suddenly, I can no longer connect via SQL Server Object Explorer to the .mdf database file and get the following error: The database 'aspnet-DevilsTowerMVC-20180327093314' cannot be opened because it is version 852. This server supports version 782 and earlier. A downgrade path is not supported. Could not open new database 'aspnet-DevilsTowerMVC

ASP.NET Identity 2.1 - Password Reset Invalid Tokens

若如初见. 提交于 2019-12-08 10:34:19
问题 ASP.NET Identity is returning an 'Invalid token.' response when resetting a password for users. I've tried the following: URL Encode the code before sending email URL Encode & Decode the code before and after Copying the code to make sure it matches what was sent Ensured my user email is confirmed (I heard that could be a problem) Created a custom UserManager/Store etc. This is my email code: var user = await UserManager.FindByNameAsync(model.Email); var code = await UserManager

Web API 2 + MVC 5 Share Identity Table

 ̄綄美尐妖づ 提交于 2019-12-08 09:12:02
问题 I have a web API and MVC5 sharing the same Identity Table. The Context belonging to the Web API: public partial class CrestfineContext: IdentityDbContext<ApplicationUser> { public CrestfineContext(): base("WelbeckDatabase", throwIfV1Schema: false) { } protected override void OnModelCreating(DbModelBuilder builder) { builder.Conventions.Remove<PluralizingTableNameConvention>(); builder.Entity<IdentityUserClaim>().ToTable("UserClaim").HasKey<Int32>(r => r.Id); builder.Entity<IdentityUserLogin>(

OAuth Refresh Token does not deserialize / invalid_grant

妖精的绣舞 提交于 2019-12-08 09:03:32
问题 I have followed the wonderful tutorial by Taiser Joudah for implementing refresh tokens with Asp.Net Web Api 2 and Owin. It all went so well...except I can't get it to work. :-) It all "seems" like it works up until the point I request a refresh token. Then all I get back is: “error”: “invalid_grant” and no description to go with. One of the comments on that post had the same symptom and the response was to generate a MachineKey for the web.config. I tried this but it didn't help. And I'm