Skip to content

Instantly share code, notes, and snippets.

@thomashagstrom
Last active January 11, 2019 13:09
Show Gist options
  • Save thomashagstrom/593eff10b5a47758790bd89392d94690 to your computer and use it in GitHub Desktop.
Save thomashagstrom/593eff10b5a47758790bd89392d94690 to your computer and use it in GitHub Desktop.
DropboxService.Authorize
/// <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