mirror of https://github.com/icedream/npsharp.git
add license key auth and an accessor for the internal RPC client
parent
817007c135
commit
612fd05702
|
@ -34,6 +34,11 @@ namespace NPSharp.NP
|
|||
_log = LogManager.GetLogger("NPClient");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The internal RPC client.
|
||||
/// </summary>
|
||||
public RPCClientStream RPCClient { get { return _rpc; } }
|
||||
|
||||
/// <summary>
|
||||
/// The assigned NP user ID. Will be set on successful authentication.
|
||||
/// </summary>
|
||||
|
@ -137,6 +142,33 @@ namespace NPSharp.NP
|
|||
_rpc.Send(new AuthenticateWithTokenMessage {Token = token});
|
||||
|
||||
return await tcs.Task;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Authenticates this connection via a platform-specific license key. This may very well include ""
|
||||
/// if the server chooses to allow anonymous logon.
|
||||
/// </summary>
|
||||
/// <param name="key">The license key to use for authentication</param>
|
||||
/// <returns>True if the login succeeded, otherwise false.</returns>
|
||||
public async Task<bool> AuthenticateWithLicenseKey(string key)
|
||||
{
|
||||
var tcs = new TaskCompletionSource<bool>();
|
||||
|
||||
_rpc.AttachHandlerForNextMessage(packet =>
|
||||
{
|
||||
var result = packet as AuthenticateResultMessage;
|
||||
if (result == null)
|
||||
return;
|
||||
|
||||
if (result.Result != 0)
|
||||
tcs.SetResult(false);
|
||||
LoginId = result.NPID;
|
||||
SessionToken = result.SessionToken;
|
||||
tcs.SetResult(true);
|
||||
});
|
||||
_rpc.Send(new AuthenticateWithKeyMessage { LicenseKey = key });
|
||||
|
||||
return await tcs.Task;
|
||||
}
|
||||
|
||||
// TODO: Try to use an exception for failed action instead
|
||||
|
|
Loading…
Reference in New Issue