/// <summary> /// Links a <see cref="ParseUser" /> to a Facebook account, allowing you to use Facebook /// for authentication, and providing access to Facebook data for the user. /// /// The user will be logged in through Facebook's OAuth web flow using the Windows /// WebAuthenticationBroker. /// </summary> /// <param name="user">The user to link with Facebook.</param> /// <param name="permissions">A list of Facebook permissions to request.</param> /// <param name="cancellationToken">The cancellation token.</param> public static async Task LinkAsync(ParseUser user, IEnumerable <string> permissions, CancellationToken cancellationToken) { var cts = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken); authProvider.Permissions = permissions; Action <Uri> navigate = async uri => { var result = await WebAuthenticationBroker.AuthenticateAsync(WebAuthenticationOptions.None, uri, FacebookAuthenticationProvider.ResponseUrl); if (result.ResponseStatus != WebAuthenticationStatus.Success) { cts.Cancel(); } else { authProvider.HandleNavigation(new Uri(result.ResponseData)); } }; authProvider.Navigate += navigate; try { await user.LinkWithAsync("facebook", cts.Token); } finally { authProvider.Navigate -= navigate; } }
/// <summary> /// Links a <see cref="ParseUser" /> to a Facebook account, allowing you to use Facebook /// for authentication, and providing access to Facebook data for the user. /// </summary> /// <param name="user">The user to link to a Facebook account.</param> /// <param name="facebookId">The user's Facebook ID.</param> /// <param name="accessToken">A valid access token for the user.</param> /// <param name="expiration">The expiration date of the access token.</param> /// <param name="cancellationToken">The cancellation token.</param> public static Task LinkAsync(ParseUser user, string facebookId, string accessToken, DateTime expiration, CancellationToken cancellationToken) { return(user.LinkWithAsync("facebook", authProvider.GetAuthData(facebookId, accessToken, expiration), cancellationToken)); }
/// <summary> /// Links a <see cref="ParseUser" /> to a Facebook account, allowing you to use Facebook /// for authentication, and providing access to Facebook data for the user. /// /// The user will be logged in through Facebook's OAuth web flow, so you must supply a /// <paramref name="webView"/> that will be navigated to Facebook's authentication pages. /// </summary> /// <param name="user">The user to link with Facebook.</param> /// <param name="webView">A web view that will be used to present the authorization pages /// to the user.</param> /// <param name="permissions">A list of Facebook permissions to request.</param> /// <param name="cancellationToken">The cancellation token.</param> public static async Task LinkAsync(ParseUser user, WebBrowser webView, IEnumerable<string> permissions, CancellationToken cancellationToken) { authProvider.Permissions = permissions; LoadCompletedEventHandler loadCompleted = (_, e) => authProvider.HandleNavigation(e.Uri); webView.LoadCompleted += loadCompleted; Action<Uri> navigate = uri => webView.Navigate(uri); authProvider.Navigate += navigate; await user.LinkWithAsync("facebook", cancellationToken); authProvider.Navigate -= navigate; webView.LoadCompleted -= loadCompleted; }
/// <summary> /// Links a <see cref="ParseUser" /> to a Facebook account, allowing you to use Facebook /// for authentication, and providing access to Facebook data for the user. /// /// The user will be logged in through Facebook's OAuth web flow, so you must supply a /// <paramref name="webView"/> that will be navigated to Facebook's authentication pages. /// </summary> /// <param name="user">The user to link with Facebook.</param> /// <param name="webView">A web view that will be used to present the authorization pages /// to the user.</param> /// <param name="permissions">A list of Facebook permissions to request.</param> /// <param name="cancellationToken">The cancellation token.</param> public static async Task LinkAsync(ParseUser user, WebBrowser webView, IEnumerable <string> permissions, CancellationToken cancellationToken) { authProvider.Permissions = permissions; LoadCompletedEventHandler loadCompleted = (_, e) => authProvider.HandleNavigation(e.Uri); webView.LoadCompleted += loadCompleted; Action <Uri> navigate = uri => webView.Navigate(uri); authProvider.Navigate += navigate; await user.LinkWithAsync("facebook", cancellationToken); authProvider.Navigate -= navigate; webView.LoadCompleted -= loadCompleted; }
/// <summary> /// Links a <see cref="ParseUser" /> to a Facebook account, allowing you to use Facebook /// for authentication, and providing access to Facebook data for the user. /// /// The user will be logged in through Facebook's OAuth web flow using the Windows /// WebAuthenticationBroker. /// </summary> /// <param name="user">The user to link with Facebook.</param> /// <param name="permissions">A list of Facebook permissions to request.</param> /// <param name="cancellationToken">The cancellation token.</param> public static async Task LinkAsync(ParseUser user, IEnumerable<string> permissions, CancellationToken cancellationToken) { var cts = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken); authProvider.Permissions = permissions; Action<Uri> navigate = async uri => { var result = await WebAuthenticationBroker.AuthenticateAsync(WebAuthenticationOptions.None, uri, FacebookAuthenticationProvider.ResponseUrl); if (result.ResponseStatus != WebAuthenticationStatus.Success) { cts.Cancel(); } else { authProvider.HandleNavigation(new Uri(result.ResponseData)); } }; authProvider.Navigate += navigate; try { await user.LinkWithAsync("facebook", cts.Token); } finally { authProvider.Navigate -= navigate; } }
/// <summary> /// Links a <see cref="ParseUser" /> to a Facebook account, allowing you to use Facebook /// for authentication, and providing access to Facebook data for the user. /// </summary> /// <param name="user">The user to link to a Facebook account.</param> /// <param name="facebookId">The user's Facebook ID.</param> /// <param name="accessToken">A valid access token for the user.</param> /// <param name="expiration">The expiration date of the access token.</param> /// <param name="cancellationToken">The cancellation token.</param> public static Task LinkAsync(ParseUser user, string facebookId, string accessToken, DateTime expiration, CancellationToken cancellationToken) { return user.LinkWithAsync("facebook", authProvider.GetAuthData(facebookId, accessToken, expiration), cancellationToken); }