コード例 #1
0
        public ResultPage(AuthenticatonResult result, Action returnCallback)
        {
            _returnCallback = returnCallback;

            var stack = new StackLayout
            {
                VerticalOptions   = LayoutOptions.Center,
                HorizontalOptions = LayoutOptions.Center
            };

            if (result)
            {
                _account = result.Account;

                stack.Children.Add(new Label
                {
                    Text = $"Provider: {_account.ProviderName}"
                });

                stack.Children.Add(new Label
                {
                    Text = $"Id: {_account.Id}"
                });

                stack.Children.Add(new Label
                {
                    Text = $"Name: {_account.DisplayName}"
                });

                var token = _account.AccessToken;

                if (token.Expires.HasValue)
                {
                    SetExpireText();
                    stack.Children.Add(_expireLabel);
                }

                if (result.Account.RefreshesToken)
                {
                    stack.Children.Add(new Button
                    {
                        Text    = "Refresh Token",
                        Command = new Command(async() =>
                        {
                            var response = await result.Account.RefreshToken();

                            if (response)
                            {
                                SetExpireText();
                            }
                        })
                    });
                }
            }
            else
            {
                stack.Children.Add(new Label
                {
                    Text = "Authentication failed!"
                });

                stack.Children.Add(new Label
                {
                    Text = $"Reason: {result.Error}"
                });

                if (!string.IsNullOrEmpty(result.ErrorDescription))
                {
                    stack.Children.Add(new Label
                    {
                        Text = $"Description: {result.ErrorDescription}"
                    });
                }
            }



            stack.Children.Add(new Button
            {
                Text    = "Back",
                Command = new Command(returnCallback)
            });

            Content = stack;
        }
コード例 #2
0
 private void HandleResult(AuthenticatonResult result)
 {
     Device.BeginInvokeOnMainThread(() => Application.Current.MainPage = new ResultPage(
                                        result,
                                        () => Application.Current.MainPage = new StartPage()));
 }