I want to use CredentialAuthProvider and JwtAuthProvider and I have my own Person class in which I want to store username and password. Most of the fields in UserAuth and UserAuthDetails are useless to me. As far as I understand the UserAuthRepositories source code it is not necessary to implement those interfaces but just IUserAuthRepository and use my Person class as storage. Are there any other interfaces that need to be implemented so that I can use the above mentioned Authproviders or do I just override TryAuthenticate and everything is fine?
Asked
Active
Viewed 21 times
1 Answers
1
The Auth Repository interfaces does require those types but you can extend it to user your own custom types instead. This thread also lists other extensibility options available.
But you can avoid needing to use an Auth Repository altogether and use a Custom CredentialsAuthProvider where you can implement Username/Password validation using your own implementation.

mythz
- 141,670
- 29
- 246
- 390
-
Okay, that sounds like an alternative. How about the JwtAuthProvider? I want the first login to be per (Custom)CredentialsAuthProvider and any following calls to my API per JWTs. – El Hippo Apr 24 '19 at 23:17
-
The `JwtAuthProvider` is stateless so validates by just what's contained in the JWT which is generated from the authenticated user session (i.e. not UserAuth repo tables). The functionality that [requires the Auth Repo is refresh tokens](https://docs.servicestack.net/jwt-authprovider#requires-user-auth-repository-or-iusersessionsource), which if you don't have one your Custom Auth Provider would need to implement `IUserSessionSource`. – mythz Apr 24 '19 at 23:23
-
I succesfully created my own CredentialsAuthProvider but one question arises: How do I access the user data which I loaded from the database in TryAuthenticate in OnAuthenticated(...) to fill my custom session with user data? – El Hippo Apr 25 '19 at 16:16
-
@ElChipo You can use the per-request storage in `authService.Request.Items[]` Dictionary. – mythz Apr 25 '19 at 16:21