Return a custom auth response object from ServiceStack authentication

后端 未结 1 1368
青春惊慌失措
青春惊慌失措 2021-01-02 05:49

Is it possible to return a custom auth response? I already have my own custom authentication provider that inherits from CredentialsAuthProvider.

I want to return th

相关标签:
1条回答
  • 2021-01-02 06:17

    If I understand correctly, you want to return a custom response after a user authenticates against '/auth/credentials'. Since you already have your own CredentialsAuthProvider I think you could just override Authenticate and return your own response.

    Subclass of CredentialsAuthProvider

    public class MyCredentialsAuthProvider : CredentialsAuthProvider
    {
        public override object Authenticate(ServiceStack.ServiceInterface.IServiceBase authService, IAuthSession session, Auth request)
        {
            //let normal authentication happen
            var authResponse = (AuthResponse)base.Authenticate(authService, session, request);
    
            //return your own class, but take neccessary data from AuthResponse
            return new
                {
                    UserName = authResponse.UserName,
                    SessionId = authResponse.SessionId,
                    ReferrerUrl = authResponse.ReferrerUrl,
                    SessionExpires = DateTime.Now
                };
    
        }
    }
    
    0 讨论(0)
提交回复
热议问题