Last active
January 11, 2019 13:09
-
-
Save thomashagstrom/593eff10b5a47758790bd89392d94690 to your computer and use it in GitHub Desktop.
DropboxService.Authorize
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// <para>Runs the Dropbox OAuth authorization process if not yet authenticated.</para> | |
/// <para>Upon completion <seealso cref="OnAuthenticated"/> is called</para> | |
/// </summary> | |
/// <returns>An asynchronous task.</returns> | |
public async Task Authorize() | |
{ | |
if (string.IsNullOrWhiteSpace(this.AccessToken) == false) | |
{ | |
// Already authorized | |
this.OnAuthenticated?.Invoke(); | |
return; | |
} | |
if (this.GetAccessTokenFromSettings()) | |
{ | |
// Found token and set AccessToken | |
return; | |
} | |
// Run Dropbox authentication | |
this.oauth2State = Guid.NewGuid().ToString("N"); | |
var authorizeUri = DropboxOAuth2Helper.GetAuthorizeUri(OAuthResponseType.Token, "yourDrobboxAppKey", new Uri("YourDropboxRedirectUri"), this.oauth2State); | |
var webView = new WebView { Source = new UrlWebViewSource { Url = authorizeUri.AbsoluteUri } }; | |
webView.Navigating += this.WebViewOnNavigating; | |
var contentPage = new ContentPage { Content = webView }; | |
await Application.Current.MainPage.Navigation.PushModalAsync(contentPage); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment