2

Looks like there is no method to retrieve a List from the IAuthRepository or do I miss something?

I use the Redis implementation, so I need a couple of hashes or Alias keys to do some filtering too. Any hints how I can do this without implementing a custom version of all those interfaces?

I have implemented my own version of IUserAuth and there are a few new props I need and I like to search for. So where is the best place to:

  1. Create some aliases / hashes to get quick access to users with certain properties. I guess it needs some special implementation of CreateUserAuth(...) methods but don't know where to start without breaking other things...
  2. Is there any way to quickly extend the Redis implementation of IAuthRepository to get
    • a list of all users
    • lists of users matching certain criteria (keys stored under 1.)

UPDATE:

Problem 1 is solved. Created my own repo and injected it in the service. There I can do simply:

using (var redis = RedisManager.GetClient())
{
    var appUsers = redis.As<IUserAuth>();
    foundUsers = (List<IUserAuth>)appUsers.GetAll();
}

Remains the question where I can add additional keys when creating a new user without 'destroying' other functionality.

ThommyB
  • 1,456
  • 16
  • 34

1 Answers1

1

The easiest way to add custom properties to User Auth Info is to store it in the UserAuth Meta dictionary.

Optionally you can choose to use your own Custom UserAuth / UserAuth Details table by extending the UserAuth table, e.g:

public class CustomUserAuth : UserAuth
{
    public string MyProperty { get; set; }
}

Then registering a Redis Auth Repository that uses your custom table instead, e.g:

container.Register<IAuthRepository>(c =>
   new RedisAuthRepository<CustomUserAuth,UserAuthDetails>(
       c.Resolve<IRedisClientsManager>());
mythz
  • 141,670
  • 29
  • 246
  • 390
  • I probably did not express clearly what the problem is. I need something to SEARCH for a property. Assuming I add a prop 'AccountType' with values of 'SYSTEM', 'SERVICE', 'USER'. To get all 'USER' accounts, I need something like `hash:UserAuth:AccountTypes>UserId` to easily retrieve all ids of accounts of type USER. The question is, where to add this hash. – ThommyB May 02 '17 at 06:42
  • @ThommyB Redis isn't ideal for querying as you'll need to maintain your own custom indexes, you could populate a set for users in different Account Types in an [OnRegistered or OnAuthenticated Session or Auth Event](http://docs.servicestack.net/sessions). I'd also have a script that re-creates the index sets from scratch by going through each user and adding their id in their respective AccountType index. – mythz May 02 '17 at 19:38
  • Yeah your right, its kind of painful if you have more than two or three props to query on. I am using MongoDB a lot and since Server V3.x and C# driver 2.x I REALLY love it! Is the MongoDB AuthRepository provider implementation a better choice, does it have all features like the RDBMS implementations you offer? I also need a real `Role` object with additional info about applications for which a role is valid, not just a 'List' property. – ThommyB May 04 '17 at 06:47
  • @ThommyB The MonogDbAuthProvider was contributed and has been maintained by other Customers, i.e. we don't use it ourselves - but they've kept it updated (i.e. they've added support for IManageApiKeys). My preference is to use OrmLiteAuthRepository since I prefer RDBMS's, but Mongo should be fine as well. – mythz May 04 '17 at 06:51
  • Ok, I will think about giving it a try. I've done RDBMS stuff too long (> 20 years) and I am sick of maintaining schemas and mappers all the time....! Started using NoSQL about four years ago and was very skeptical. But Mongo has improved a lot, for me it is a real alternative which saves me a lot of time in many situations (not all). However, this is off-topic, I shut-up....! – ThommyB May 04 '17 at 07:06