0

Ive built a custom provider to support groups and nosql databases. And it all seems to work apart from authentication (accounts can be created end som forth without issues). I use my own entity classes which are not inherited from identityuser etc should be noted.

The issue im having is as said that running for example var loginres = await this.signInManager.PasswordSignInAsync("username", "paswd", false, false) is giving me an exception,

InvalidOperationException: No authentication handler is configured to handle the scheme: Identity.Application

The way ive setup my code is as follows:

services.AddIdentity<User, Role>()
                .AddUserStore<NoSqlUserStore<User, Role>>()
                .AddRoleStore<NoSqlRoleStore<Role>>()
                .AddUserManager<IdentityUserManager<User>>()
                .AddRoleManager<IdentityRoleManager<Role>>()
                .AddDefaultTokenProviders();

The manager classes just inherits the User and role manage classes, nothing is changed or added atm.

public class IdentityUserManager<TUser> : UserManager<TUser>
        where TUser : User, new()
    {
        public IdentityUserManager(IUserStore<TUser> store, IOptions<IdentityOptions> optionsAccessor, IPasswordHasher<TUser> passwordHasher, IEnumerable<IUserValidator<TUser>> userValidators, IEnumerable<IPasswordValidator<TUser>> passwordValidators, ILookupNormalizer keyNormalizer, IdentityErrorDescriber errors, IServiceProvider services, ILogger<IdentityUserManager<TUser>> logger)
            : base(store, optionsAccessor, passwordHasher, userValidators, passwordValidators, keyNormalizer, errors, services, logger)
        {
        }
    }

public class IdentityRoleManager<TRole> : RoleManager<TRole>
        where TRole : Role
    {
        public IdentityRoleManager(IRoleStore<TRole> store, IEnumerable<IRoleValidator<TRole>> roleValidators, ILookupNormalizer keyNormalizer, IdentityErrorDescriber errors, ILogger<RoleManager<TRole>> logger, IHttpContextAccessor contextAccessor)
            : base(store, roleValidators, keyNormalizer, errors, logger, contextAccessor)
        {
        }
    }

The signatures for the stores are as follows:

public class NoSqlRoleStore<TRole> : RoleStoreBase, IRoleStore<TRole>
        where TRole : Role, new()
    {

    }

public class NoSqlUserStore<TUser, TRole> : UserStoreBase<TUser>, //todo: include groups in rolechecking
        IUserLoginStore<TUser>,
        IUserRoleStore<TUser>,
        IUserClaimStore<TUser>,
        IUserPasswordStore<TUser>,
        IUserSecurityStampStore<TUser>,
        IUserEmailStore<TUser>,
        IUserLockoutStore<TUser>,
        IQueryableUserStore<TUser>,
        IUserTwoFactorStore<TUser>,
        IUserAuthenticationTokenStore<TUser>
        where TUser : User, IEntity, new() where TRole : Role, IEntity, new()
    {

    }

Of course they contain all interface methods, it compiles, runs and works except for the error. The User And role classes are plain entities that is somewhat similar to the provided ones.

My guess is im missing some configurationsetting (even if, as far as ive seen, that identity should provide working default in regards to this?) or something. Ive never used identity outside the default entity framework provider. But i was hoping that someone perhaps knows what is needed here? (if any more code is needed to illustrate the situation ill fix it)

Base
  • 1,061
  • 1
  • 11
  • 27

2 Answers2

2

You should define your custom UserStore

public class MyUserStore : IUserStore<CustomUser,int>,
    IUserPasswordStore<CustomUser,int>, 
    IUserSecurityStampStore<CustomUser, int>,
    IUserLoginStore<CustomUser, int>,IUserRoleStore<CustomUser,int>
        {
            //interfaces implementations
        }

Where CustomUser is your User class that realize TUser interface and 'int' is the type of yours primine key fields

If you have string primary key use that

IUserStore<CustomUser>

Than if you need define CustomUserManager

  public class CustomUserManager: UserManager<CustomeUser,int> // UserManager<CustomeUser> if primary is string
    {

    }
DespeiL
  • 993
  • 9
  • 28
  • I use the default, string, at the moment. But i can try see replacing the generics and explicitly setting string will help (seems strange it would make any difference but worth trying). – Base Jun 20 '16 at 12:52
  • 1
    for default string implement interfaces just with your CustomUser class – DespeiL Jun 20 '16 at 12:53
  • 1
    It was not the generics causing it but i had left out a crucial configurationpart that i totally missed while bugchecking. So a human error on my part. I totally missed UseIdentity() in configure method. Want thank you however since your suggested adjustments caused me to realise it (one can easily get blind for the most obvious while bugsearching ;) ). So ill upvote :) – Base Jun 20 '16 at 13:22
1

The cause was malplaced app.UseIdentity(). As mentioned in No authentication handler is configured to authenticate for the scheme: Microsoft.AspNet.Identity.External

Community
  • 1
  • 1
Base
  • 1,061
  • 1
  • 11
  • 27