コード例 #1
0
        /// <summary>
        /// logout session
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnLogout_Click(object sender, RoutedEventArgs e)
        {
            var answer = MessageBox.Show("Are you sure you want to logout?", "Logout", MessageBoxButton.YesNo, MessageBoxImage.Warning);

            if (answer == MessageBoxResult.Yes)
            {
                session = null;
                webBrowser.Visibility = Visibility.Visible;
                mainWindow.Height     = 600;
                TokenConfig.writeTokens("", "");
                webBrowser.Source = new Uri(this.request);
            }
        }
コード例 #2
0
        /// <summary>
        /// Web Browser redirection in case of first login/logout or corrupted tokens
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void webBrowser_Navigated(object sender, NavigationEventArgs e)
        {
            if (e.Uri.Host == BoxManagerConst.redirecturi)
            {
                // grab access_token and oauth_verifier
                IDictionary <string, string> keyDictionary = new Dictionary <string, string>();
                var qSplit = e.Uri.Query.Split('?');
                foreach (var kvp in qSplit[qSplit.Length - 1].Split('&'))
                {
                    var kvpSplit = kvp.Split('=');
                    if (kvpSplit.Length == 2)
                    {
                        keyDictionary.Add(kvpSplit[0], kvpSplit[1]);
                    }
                }

                AuthCode = keyDictionary["code"];
                webBrowser.Visibility = Visibility.Hidden;
                try
                {
                    session = await Client.Auth.AuthenticateAsync(AuthCode);

                    TokenConfig.writeTokens(session.AccessToken, session.RefreshToken);
                    Box.V2.Models.BoxUser u = await Client.UsersManager.GetCurrentUserInformationAsync();

                    loggedin_user        = u.Login;
                    lblLoggedInUser.Text = loggedin_user;
                    main.Visibility      = Visibility.Visible;
                    txtAccessToken.Text  = session.AccessToken;
                    txtRefreshToken.Text = session.RefreshToken;
                    mainWindow.Height    = formHeight;
                }
                catch (BoxException ex)
                {
                    MessageBox.Show(ex.Message, "Exception", MessageBoxButton.OK, MessageBoxImage.Error);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Exception", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
        }
コード例 #3
0
 /// <summary>
 /// Writes new tokens into tokens.xml file whenever new tokesn are obtained or refreshed
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 void Auth_SessionAuthenticated(object sender, SessionAuthenticatedEventArgs e)
 {
     TokenConfig.writeTokens(e.Session.AccessToken, e.Session.RefreshToken);
 }
コード例 #4
0
        public static OAuthSession getSession()
        {
            OAuthSession session = new OAuthSession(TokenConfig.readToken("AccessToken"), TokenConfig.readToken("RefreshToken"), int.Parse(TokenConfig.readToken("ExpiresIn")), "Bearer");

            return(session);
        }