Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OWIN/Identity 2.0 - Changing pk from string to GUID

I am attempting to change asp.net identity's pk system from database nvarchar(128) -> uniqueidentifier and in code from string -> Guid. Following this article based on changing the pk to an int32 I have just one problem I can't seem to get around.

In my Startup.Auth.cs class I have changed the following

app.UseCookieAuthentication(new CookieAuthenticationOptions
        {
            AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
            LoginPath = new PathString("/Account/Login"),
            Provider = new CookieAuthenticationProvider
            {   //error on the line below
                OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser, Guid>(TimeSpan.FromMinutes(20), (manager, user) => user.GenerateUserIdentityAsync(manager), (identity) => Guid.Parse(identity.GetUserId()))
            }
        });  

and am getting two errors that I cannot comprehend. The structure of Identity confuses the hell out of me with so many generics. I understand it says it is receiving the wrong parameter type but I have no idea how to remedy the issue.

Errors

Error 1 The best overloaded method match for 'Microsoft.AspNet.Identity.Owin.SecurityStampValidator.OnValidateIdentity(System.TimeSpan, System.Func>, System.Func)' has some invalid arguments

Error 2 Argument 2: cannot convert from 'lambda expression' to 'System.Func>'

Can anyone offer a little insight?

like image 939
Adrian Avatar asked Jul 30 '14 23:07

Adrian


1 Answers

  app.UseCookieAuthentication(new CookieAuthenticationOptions
        {
            AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
            LoginPath = new PathString("/_layouts/Account/Login"),
            Provider = new CookieAuthenticationProvider
            {
                // Enables the application to validate the security stamp when the user logs in.
                // This is a security feature which is used when you change a password or add an external login to your account.  
                OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, WebUser,Guid>(
                    validateInterval: TimeSpan.FromMinutes(30),
                     regenerateIdentityCallback: (manager, user) => 
                    user.GenerateUserIdentityAsync(manager), 
                getUserIdCallback:(id)=>(Guid.Parse(id.GetUserId())))

            }
        });        
like image 97
Hossam Arafa Avatar answered Oct 04 '22 23:10

Hossam Arafa