asp.net-identity

UserManager.AddToRole not working - Foreign Key error

假装没事ソ 提交于 2019-12-10 09:46:50
问题 In my ASP.NET MVC application I have some code which should be fairly trivial: UserManager.AddToRole(user.id, "Admin"); I just get this error... The INSERT statement conflicted with the FOREIGN KEY constraint "FK_dbo.AspNetUserRoles_dbo.AspNetRoles_RoleId". The conflict occurred in database "TestDatabase", table "dbo.AspNetRoles", column 'Id'. My ASP.NET Identity Framework is custom in that everything uses Guid as keys instead of int or string . Any ideas what is causing this? Edits, as per

Hosting ASOS with TestServer

不想你离开。 提交于 2019-12-10 09:44:15
问题 I have an OpenIdDict authentication server which is based on AspNet.Security.OpenIdConnect.Server . The setup works as expected. Now to do some in process integration;system tests which span the whole backend architecture I use the TestServer class. Why I test like this is another question Most test code coverage with least amount of work It has been decided to not do unit tests... (too much work they say) Real integration tests which span much less code where also seen as to much work when I

Customize Bearer token JSON result in ASP.NET WebApi 2

邮差的信 提交于 2019-12-10 04:01:54
问题 I walkthrough this official ASP.NET tutorial, and the bearer token is published as below JSON. { "access_token":"boQtj0SCGz2GFGz[...]", "token_type":"bearer", "expires_in":1209599, "userName":"Alice", ".issued":"Mon, 14 Oct 2013 06:53:32 GMT", ".expires":"Mon, 28 Oct 2013 06:53:32 GMT" } I'd like to add user profile properties along with the above resul in order to reduce number of requests from clients. The example is as below... { "access_token":"boQtj0SCGz2GFGz[...]", "token_type":"bearer"

ASP.NET MVC tries to load older version of Owin assembly

五迷三道 提交于 2019-12-10 03:17:16
问题 As a bit of context, I'm developing an ASP.NET MVC 5 application that uses OAuth-based authentication via Microsoft's OWIN implementation, for Facebook and Google only at this stage. Currently (as of v3.0.0, git-commit 4932c2f), the FacebookAuthenticationOptions and GoogleOAuth2AuthenticationOptions don't provide any property to force Facebook nor Google respectively to reauthenticate users (via appending the appropriate query string parameters) when signing in. Initially, I set out to

Identity Authorize Attribute Roles with Web API

百般思念 提交于 2019-12-10 03:09:17
问题 I have a small Web API application that uses Identity to manage users using Owin Bearer Tokens. The basics of this implementation work fine: I can register a user, login a user and access Web API end points that are marked with [Authorize] . My next step is to limit Web API endpoints using roles. For example, a controller that only users in the Admin role can access. I've created the Admin user as below and I add them to the Admin role. However when I update my existing controllers from

IdentityStoreManager could not be found after upgrading Microsoft.AspNet.Identity to rc1

蓝咒 提交于 2019-12-10 02:31:57
问题 After Upgrading Microsoft.AspNet.Identity.Core to 1.0.0-rc1 several errors appear in the AccountController.cs And AppModel.cs classes which are generated by the default MVC5 templates in Visual Studio 2013. Are there any release notes to explain how to resolve the breaking changes? 回答1: Update the following nuget packages: Microsoft ASP.NET Identity EntityFramework version="1.0.0-rc1" Microsoft.Owin.Security version="2.0.0-rc1" Microsoft.Owin.Security.OAuth version="2.0.0-rc1" Get these:

MVC User.Identity.Name with first and last names

試著忘記壹切 提交于 2019-12-10 02:21:35
问题 I have added First and Last name to the ApplicationUser Class. public class ApplicationUser : IdentityUser { public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager) { // Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie); // Add custom user claims here return userIdentity; } public string

The property 'Claims' on type 'AspNetUser' is not a navigation property

坚强是说给别人听的谎言 提交于 2019-12-10 02:06:42
问题 I'm using ASP.NET Identity 2.2. I'm migrating the ASP.NET old membership to new Identity system. I am following the steps mentioned in this article for performing the migration. I have extended IdentityUser and added few more properties like follows: public partial class AspNetUser : IdentityUser { public AspNetUser() { CreateDate = DateTime.Now; IsApproved = false; LastLoginDate = DateTime.Now; LastActivityDate = DateTime.Now; LastPasswordChangedDate = DateTime.Now; LastLockoutDate =

DataProtectionProvider in the Identity sample project

喜你入骨 提交于 2019-12-10 01:14:10
问题 The official Identity 2 sample project has the code below in UserManager.Create() public static UserManager Create(IdentityFactoryOptions<UserManager> options, IOwinContext context) { //...etc... // --- what does this block do? --- var dataProtectionProvider = options.DataProtectionProvider; if (dataProtectionProvider != null) { manager.UserTokenProvider = new DataProtectorTokenProvider<User>(dataProtectionProvider.Create("ASP.NET Identity")); } // -------------------------------- //...etc...

Can not instantiate proxy…Could not find a parameterless constructor

痞子三分冷 提交于 2019-12-10 01:06:42
问题 I am trying to create a unit test using Moq which tests the MongoDB.AspNet.Identity V2 provider. This line is giving me grief: var appUser = new Mock<PreRegistrationMVC.Models.ApplicationUser>(); var userStore = new Mock<MongoDB.AspNet.Identity.UserStore<PreRegistrationMVC.Models.ApplicationUser>>(); It seems the userStore won't instantiate properly here is the error. Castle.DynamicProxy.InvalidProxyConstructorArgumentsException was unhandled by user code HResult=-2147024809 Message=Can not