-
Notifications
You must be signed in to change notification settings - Fork 1
RPC Authentication
Alexander edited this page Aug 24, 2022
·
2 revisions
Neon is supporting any kind of custom authentication of clients.
You need to define a factory and auth session same as you defined it for calls:
public class AuthSessionFactory : IAuthSessionFactory
{
public AuthSessionServerBase CreateSession(AuthSessionContext sessionContext)
{
return new AuthSession(sessionContext);
}
}public class AuthSession : AuthSessionServer
{
public AuthSession(AuthSessionContext sessionContext) : base(sessionContext)
{
}
protected override object Auth(object arg)
{
if (arg.ToString() != "cool password")
throw new RemotingException("Wrong credentials", RemotingException.StatusCodeEnum.AccessDenied);
return "session_key";
}
}There's another version of session AuthSessionServerAsync if you need asynchronous auth operation
Add configurationServer.AuthSessionFactory = new AuthSessionFactory() to the server configuration
And now you need to call client.StartSessionWithAuth(object arg) instead of client.StartSessionNoAuth()
Exceptions on authentication are processed in general way (any Exception is converted to RemoteException and raised on the client)
If authentication method executed without any exception, you may get the result of authentication:
//Server
public class Session : RpcSessionImpl
{
public Session(RpcSessionContext sessionContext) : base(sessionContext)
{
var authSession = sessionContext.AuthSession as AuthSession;
//get any info here
}
}//Client
public class Session : RpcSessionImpl
{
public Session(RpcSessionContext sessionContext) : base(sessionContext)
{
var authSession = sessionContext.AuthSession as AuthSessionClient;
var result = authSession.AuthResult; //an object returned from the server
}
}