Exemplo n.º 1
0
        protected async override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            AuthorizeDialog     authorizeDialog = new AuthorizeDialog();
            ContentDialogResult result          = await authorizeDialog.ShowAsync();

            if (result == ContentDialogResult.Primary)
            {
                ConnectionLine.Text = ApplicationContext.getConnectionLine();
                TitleTextBlock.Text = "Доступ";
                //myFrame.Navigate(typeof(AccessesPage), this);
            }
        }
Exemplo n.º 2
0
        protected async override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            AuthorizeDialog     authorizeDialog = new AuthorizeDialog();
            ContentDialogResult result          = await authorizeDialog.ShowAsync();

            if (result == ContentDialogResult.Primary)
            {
                ConnectionLine.Text = ApplicationContext.getConnectionLine() + " ver. " + VersionUtil.GetAppVersion();
                TitleTextBlock.Text = "База знаний";
                myFrame.Navigate(typeof(KnowPage), this);
            }
        }
Exemplo n.º 3
0
        public override async Task AuthorizeAsync()
        {
            if (LocalAccessToken.IsUseable)
            {
                AccessToken = LocalAccessToken.Value;
                Uid         = LocalAccessToken.Uid;
            }
            else
            {
                var authorizeUri        = new Uri("https://api.weibo.com/oauth2/authorize");
                var authorizeUriBuilder = new UriBuilder(authorizeUri);
                var authorizeQuery      = new Dictionary <string, string>()
                {
                    ["client_id"]    = AppKey,
                    ["redirect_uri"] = RedirectUri
                };
                if (Scope != null)
                {
                    authorizeQuery["scope"] = Scope;
                }
                if (!CultureInfo.CurrentUICulture.Name.StartsWith("zh", StringComparison.OrdinalIgnoreCase))
                {
                    authorizeQuery["language"] = "en";
                }
                authorizeUriBuilder.Query = ToUriQuery(authorizeQuery);
                authorizeUri = authorizeUriBuilder.Uri;

                var authorizeDialog = new AuthorizeDialog(authorizeUri);
                var authorizeResult = authorizeDialog.ShowDialog();
                if (authorizeResult == DialogResult.OK)
                {
                    var getAccessTokenQuery = new Dictionary <string, string>()
                    {
                        ["client_id"]     = AppKey,
                        ["client_secret"] = AppSecret,
                        ["grant_type"]    = "authorization_code",
                        ["code"]          = authorizeDialog.AuthorizeCode,
                        ["redirect_uri"]  = RedirectUri
                    };

                    var requestTime = DateTime.Now;
                    var json        = await HttpPostAsync("https://api.weibo.com/oauth2/access_token", getAccessTokenQuery, false);

                    var accessToken = JsonConvert.DeserializeObject <AccessToken>(json);

                    AccessToken = accessToken.Value;
                    Uid         = accessToken.Uid;

                    LocalAccessToken.Value     = accessToken.Value;
                    LocalAccessToken.Uid       = accessToken.Uid;
                    LocalAccessToken.ExpiresAt = requestTime.AddSeconds(accessToken.ExpiresIn);
                }
                else if (authorizeResult == DialogResult.Cancel)
                {
                    throw new UserCancelAuthorizeException();
                }
                else
                {
                    throw new AuthorizationException();
                }
            }
        }