Example #1
0
            public OAuthWindow(Uri startUri, Uri redirectUri, OAuthUIOptions options)
            {
                _startUri    = startUri;
                _redirectUri = redirectUri;

                _browser                = new WebBrowser();
                _browser.Navigating    += BrowserOnNavigating;
                _browser.LoadCompleted += BrowserOnLoadCompleted;

                this.WindowStartupLocation = WindowStartupLocation.CenterOwner;
                this.WindowStyle           = WindowStyle.ToolWindow;
                this.Loaded += OnLoaded;
                this.Content = _browser;

                _options = options ?? new OAuthUIOptions();
                if (_options.Width != null)
                {
                    Width = _options.Width.Value;
                }
                if (_options.Height != null)
                {
                    Height = _options.Height.Value;
                }

                if (_options.Owner != null)
                {
                    var helper = new WindowInteropHelper(this);
                    helper.Owner = _options.Owner.Value;
                }
            }
Example #2
0
        public Task <OAuthResult> AuthorizeAsync(Uri startUri, Uri redirectUri, OAuthUIOptions options = null)
        {
            var window = new OAuthWindow(startUri, redirectUri, options);
            var tcs    = new TaskCompletionSource <OAuthResult>();

            if (window.ShowDialog() == true)
            {
                tcs.SetResult(window.Result);
            }
            else
            {
                tcs.SetResult(new OAuthResult(string.Empty, OAuthStatus.Cancelled));
            }
            return(tcs.Task);
        }
Example #3
0
 public Task <OAuthResult> AuthorizeAsync(Uri startUri, Uri redirectUri, OAuthUIOptions options = null)
 {
     throw BadTargetPlatformException();
 }
Example #4
0
        public async Task <OAuthResult> AuthorizeAsync(Uri startUri, Uri redirectUri, OAuthUIOptions options = null)
        {
            var result =
                await WebAuthenticationBroker.AuthenticateAsync(
                    WebAuthenticationOptions.None,
                    startUri,
                    redirectUri);

            OAuthStatus status;

            switch (result.ResponseStatus)
            {
            case WebAuthenticationStatus.Success:
                status = OAuthStatus.Success;
                break;

            case WebAuthenticationStatus.UserCancel:
                status = OAuthStatus.Cancelled;
                break;

            case WebAuthenticationStatus.ErrorHttp:
                status = OAuthStatus.Error;
                break;

            default:
                throw new ArgumentOutOfRangeException("Unexpected ResponseStatus value: " + result.ResponseStatus);
            }

            return(new OAuthResult(result.ResponseData, status));
        }