Beispiel #1
0
        private void DoAuth()
        {
            var lkClient         = LaunchKeyClientSingleton.GetInstanceFromConfig();
            var lkSessionManager = new LaunchKeyAsyncHelper(lkClient);

            InvokeSetButtonStatus("Contacting LaunchKey ... ");


            lkSessionManager.BeginAuthentication(
                username: txtUsername.Text,
                onSuccess: authResponse =>
            {
                InvokeSetButtonStatus("Launch Request Sent ... ");
                lkSessionManager.BeginPoll(
                    authRequest: authResponse.AuthRequest,
                    onSuccess: pollResponse =>
                {
                    if (lkClient.IsAuthorized(authResponse.AuthRequest, pollResponse))
                    {
                        InvokeSetButtonStatus("Success. :)");
                        if (AuthenticationSuccess != null)
                        {
                            this.Invoke(AuthenticationSuccess, pollResponse);
                        }
                    }
                    else
                    {
                        InvokeSetButtonStatus("Device rejected. :(");
                        this.DelayEnableAuth();
                    }
                },
                    onFailure: pollResponse =>
                {
                    InvokeSetButtonStatus("Error Authenticating :(");
                    this.DelayEnableAuth();
                }
                    );
            },
                onFailure: authResponse =>
            {
                InvokeSetButtonStatus("Launch Request Failed :(");
                this.DelayEnableAuth();
            }
                );
        }
Beispiel #2
0
        public MainWindow()
        {
            InitializeComponent();

            this.lkAsyncHelper = new LaunchKeyAsyncHelper(LaunchKeyClientSingleton.GetInstanceFromConfig());

            this.treasureControl.LogOutClicked += (s, e) =>
            {
                // send the launch key deorbit request
                // this should mark our current auth as expired, causing our continuous poll to die out
                this.lkAsyncHelper.BeginLogs(LogsAction.Revoke, LogsStatus.Granted, this.currentAuth.DecryptedAuth.AuthRequest, _ => lkAsyncHelper.ForcePollNow(), _ => lkAsyncHelper.ForcePollNow());
            };

            this.lkLoginControl.AuthenticationSuccess += (authResponse) =>
            {
                this.currentAuth = authResponse;

                // hide the login view
                this.pnlLogin.Visible = false;

                // show our treasure
                this.pnlTreasure.Visible = true;

                this.tspLabel.Text = "User authenticated, will check again in 1 minute ... ";
                this.tspForcePollButton.Visible = true;

                // tell our async helper to continuously poll LaunchKey to validate our session
                this.lkAsyncHelper.BeginContinuousPoll(this.currentAuth.DecryptedAuth.AuthRequest,
                                                       onDeorbit: deorbitResponse =>
                {
                    // this code will execute if the session is killed, either by us or by the device
                    this.Invoke((Action)(() =>
                    {
                        MessageBox.Show("Session was deorbited.", "LaunchKey", MessageBoxButtons.OK, MessageBoxIcon.Information);

                        this.lkAsyncHelper.BeginLogs(LogsAction.Revoke, LogsStatus.Granted, this.currentAuth.DecryptedAuth.AuthRequest, null, null);

                        // bring us back to login, hide the treasure
                        this.lkLoginControl.Reset();
                        this.treasureControl.Reset();
                        this.pnlLogin.Visible = true;
                        this.pnlTreasure.Visible = false;
                        this.tspLabel.Text = string.Empty;
                        this.tspForcePollButton.Visible = false;
                    }));

                    // kill our local session
                    this.currentAuth = null;
                },
                                                       onPollBegin: () =>
                {
                    this.Invoke((Action)(() =>
                    {
                        this.tspLabel.Text = "Polling ... ";
                    }));
                },
                                                       onPollSuccesful: () =>
                {
                    this.Invoke((Action)(() =>
                    {
                        this.tspLabel.Text = "User authenticated, will check again in 1 minute ... ";
                    }));
                }
                                                       );
            };
        }