diff options
Diffstat (limited to 'src/DotNetOpenAuth.OAuth2.Client.UI/OAuth2/ClientAuthorizationView.cs')
-rw-r--r-- | src/DotNetOpenAuth.OAuth2.Client.UI/OAuth2/ClientAuthorizationView.cs | 33 |
1 files changed, 23 insertions, 10 deletions
diff --git a/src/DotNetOpenAuth.OAuth2.Client.UI/OAuth2/ClientAuthorizationView.cs b/src/DotNetOpenAuth.OAuth2.Client.UI/OAuth2/ClientAuthorizationView.cs index 2c90c99..8f1c5f6 100644 --- a/src/DotNetOpenAuth.OAuth2.Client.UI/OAuth2/ClientAuthorizationView.cs +++ b/src/DotNetOpenAuth.OAuth2.Client.UI/OAuth2/ClientAuthorizationView.cs @@ -13,6 +13,8 @@ namespace DotNetOpenAuth.OAuth2 { using System.Drawing; using System.Linq; using System.Text; + using System.Threading; + using System.Threading.Tasks; using System.Windows.Forms; using DotNetOpenAuth.Messaging; @@ -93,6 +95,14 @@ namespace DotNetOpenAuth.OAuth2 { } /// <summary> + /// Gets or sets a value indicating whether the implicit grant type should be used instead of the authorization code grant. + /// </summary> + /// <value> + /// <c>true</c> if [request implicit grant]; otherwise, <c>false</c>. + /// </value> + public bool RequestImplicitGrant { get; set; } + + /// <summary> /// Called when the authorization flow has been completed. /// </summary> protected virtual void OnCompleted() { @@ -108,10 +118,10 @@ namespace DotNetOpenAuth.OAuth2 { /// <param name="e">An <see cref="T:System.EventArgs"/> that contains the event data.</param> [SuppressMessage("Microsoft.Usage", "CA2234:PassSystemUriObjectsInsteadOfStrings", Justification = "Avoid bug in .NET WebBrowser control.")] [SuppressMessage("Microsoft.Security", "CA2122:DoNotIndirectlyExposeMethodsWithLinkDemands", Justification = "It's a new instance we control.")] - protected override void OnLoad(EventArgs e) { + protected override async void OnLoad(EventArgs e) { base.OnLoad(e); - Uri authorizationUrl = this.Client.RequestUserAuthorization(this.Authorization); + Uri authorizationUrl = await this.Client.RequestUserAuthorizationAsync(this.Authorization, implicitResponseType: this.RequestImplicitGrant); this.webBrowser1.Navigate(authorizationUrl.AbsoluteUri); // use AbsoluteUri to workaround bug in WebBrowser that calls Uri.ToString instead of Uri.AbsoluteUri leading to escaping errors. } @@ -133,18 +143,21 @@ namespace DotNetOpenAuth.OAuth2 { /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.Windows.Forms.WebBrowserNavigatingEventArgs"/> instance containing the event data.</param> - private void WebBrowser1_Navigating(object sender, WebBrowserNavigatingEventArgs e) { - this.ProcessLocationChanged(e.Url); + private async void WebBrowser1_Navigating(object sender, WebBrowserNavigatingEventArgs e) { + await this.ProcessLocationChangedAsync(e.Url); } /// <summary> /// Processes changes in the URL the browser has navigated to. /// </summary> /// <param name="location">The location.</param> - private void ProcessLocationChanged(Uri location) { + /// <returns> + /// A task that completes with the asynchronous operation. + /// </returns> + private async Task ProcessLocationChangedAsync(Uri location) { if (SignificantlyEqual(location, this.Authorization.Callback, UriComponents.SchemeAndServer | UriComponents.Path)) { try { - this.Client.ProcessUserAuthorization(location, this.Authorization); + await this.Client.ProcessUserAuthorizationAsync(location, this.Authorization); } catch (ProtocolException ex) { var options = (MessageBoxOptions)0; if (this.RightToLeft == System.Windows.Forms.RightToLeft.Yes) { @@ -162,8 +175,8 @@ namespace DotNetOpenAuth.OAuth2 { /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.Windows.Forms.WebBrowserNavigatedEventArgs"/> instance containing the event data.</param> - private void WebBrowser1_Navigated(object sender, WebBrowserNavigatedEventArgs e) { - this.ProcessLocationChanged(e.Url); + private async void WebBrowser1_Navigated(object sender, WebBrowserNavigatedEventArgs e) { + await this.ProcessLocationChangedAsync(e.Url); } /// <summary> @@ -171,8 +184,8 @@ namespace DotNetOpenAuth.OAuth2 { /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> - private void WebBrowser1_LocationChanged(object sender, EventArgs e) { - this.ProcessLocationChanged(this.webBrowser1.Url); + private async void WebBrowser1_LocationChanged(object sender, EventArgs e) { + await this.ProcessLocationChangedAsync(this.webBrowser1.Url); } } } |