From 612fd057024efd1edb1a073e51eb6518d6117eaa Mon Sep 17 00:00:00 2001 From: NTAuthority Date: Fri, 30 May 2014 21:55:16 +0200 Subject: [PATCH] add license key auth and an accessor for the internal RPC client --- src/client/NP/NPClient.cs | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/client/NP/NPClient.cs b/src/client/NP/NPClient.cs index 960f5cf..347cedd 100644 --- a/src/client/NP/NPClient.cs +++ b/src/client/NP/NPClient.cs @@ -34,6 +34,11 @@ namespace NPSharp.NP _log = LogManager.GetLogger("NPClient"); } + /// + /// The internal RPC client. + /// + public RPCClientStream RPCClient { get { return _rpc; } } + /// /// The assigned NP user ID. Will be set on successful authentication. /// @@ -137,6 +142,33 @@ namespace NPSharp.NP _rpc.Send(new AuthenticateWithTokenMessage {Token = token}); return await tcs.Task; + } + + /// + /// Authenticates this connection via a platform-specific license key. This may very well include "" + /// if the server chooses to allow anonymous logon. + /// + /// The license key to use for authentication + /// True if the login succeeded, otherwise false. + public async Task AuthenticateWithLicenseKey(string key) + { + var tcs = new TaskCompletionSource(); + + _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