Search code examples
servicestack

Overview of all the integrated functionality in IAuthRepository in ServiceStack


I was wondering if there is some kind of overview of all the integrated functionally for IAuthRepository (ServiceStack). I know about /register, /auth/credentials. Is there some way to get all the information from the logged in user?


Solution

  • An overview of ServiceStack Authentication is available in the docs.

    Specifically ServiceStack's IAuthRepository is just the repository used to persist Users which has providers that supports multiple back-end data stores. If you wanted to see all information stored about a user you can just inspect the contents of these 2 tables in the data store they're being stored in.

    Everything's that needed to know about them can be found by the IAuthRepository and IUserAuthRepository interfaces which defines the API that all Auth Repositories implement and the UserAuth and UserAuthDetails Data Models that they all store.

    Once a User is Authenticated the information stored about them in the Auth Repository is used to populate the Users Session, which is available in the AuthUserSession Type that's stored in the Cache, which can be resolved in your Services with:

    var session = SessionAs<AuthUserSession>();
    

    Or if you're using an extended Custom UserSession you would retrieve the Session into that instead:

    var session = SessionAs<CustomUserSession>();
    

    i.e. you should use whatever User Session Type that's registered with the AuthFeature:

     Plugins.Add(new AuthFeature(() => new CustomUserSession(), ...));