Beispiel #1
0
        /// <summary>
        /// Updates the PhoneWebAuthenticationBroker on the state of the authentication
        /// operation.  If we navigated back by pressing the back key, then the operation
        /// will be canceled.  If the browser control successfully completed the operation,
        /// signaled by its navigating to the PhoneWebAuthenticationBroker.EndUri, then we
        /// pass the results on.
        /// </summary>
        protected override void OnNavigatingFrom(NavigatingCancelEventArgs e)
        {
            // If there is an active authentication operation in progress and we have
            // finished, then we need to inform the authentication broker of the results.
            // We don't want to stop the operation prematurely, such as when navigating to
            // the start screen.
            if (WebviewAuthentication.AuthenticationInProgress && authenticationFinished)
            {
                authenticationStarted  = false;
                authenticationFinished = false;

                WebviewAuthentication.OnAuthenticationFinished(responseData, responseStatus, responseErrorDetail);
            }
        }
Beispiel #2
0
        async public void LoginWithBehavior(string permissions, FacebookLoginBehavior behavior)
        {
            switch (behavior)
            {
            case FacebookLoginBehavior.LoginBehaviorMobileInternetExplorerOnly:
            {
#if (WP8 || WINDOWS_PHONE)
                String appId = await AppAuthenticationHelper.GetFacebookConfigValue("Facebook", "AppId");

                Uri uri =
                    new Uri(
                        String.Format(
                            "https://m.facebook.com/v2.1/dialog/oauth?redirect_uri={0}%3A%2F%2Fauthorize&display=touch&state=%7B%220is_active_session%22%3A1%2C%22is_open_session%22%3A1%2C%22com.facebook.sdk_client_state%22%3A1%2C%223_method%22%3A%22browser_auth%22%7D&scope={2}&type=user_agent&client_id={1}&sdk=ios",
                            String.Format("fb{0}", appId), appId, permissions), UriKind.Absolute);

                Launcher.LaunchUriAsync(uri);
                break;
#else
                throw new NotImplementedException("Internet explorer based login is not available on Windows");
#endif
            }

            case FacebookLoginBehavior.LoginBehaviorWebViewOnly:
            {
                String appId = await AppAuthenticationHelper.GetFacebookConfigValue("Facebook", "AppId");

#if WP8 || WINDOWS_PHONE
                Uri uri =
                    new Uri(
                        String.Format(
                            "https://m.facebook.com/v2.1/dialog/oauth?redirect_uri={0}%3A%2F%2Fauthorize&display=touch&state=%7B%220is_active_session%22%3A1%2C%22is_open_session%22%3A1%2C%22com.facebook.sdk_client_state%22%3A1%2C%223_method%22%3A%22browser_auth%22%7D&scope={2}&type=user_agent&client_id={1}&sdk=ios",
                            String.Format("fb{0}", appId), appId, permissions), UriKind.Absolute);
#else
                Uri uri = await GetLoginUrl(permissions);
#endif
                WebviewAuthentication.AuthenticateAsync(WebAuthenticationOptions.None, uri, null);
                break;
            }

            case FacebookLoginBehavior.LoginBehaviorWebAuthenticationBroker:
#if WINDOWS
            {
                try
                {
                    // TODO: What to do here? LoginAsync returns inproc. Login with IE returns out of proc?
                    var result = await LoginAsync(permissions, FacebookLoginBehavior.LoginBehaviorWebAuthenticationBroker);

                    // when the results are available, launch the event handler
                    if (OnFacebookAuthenticationFinished != null)
                    {
                        OnFacebookAuthenticationFinished(result);
                    }

                    if (OnSessionStateChanged != null)
                    {
                        OnSessionStateChanged(LoginStatus.LoggedIn);
                    }
                }
                catch (FacebookOAuthException e)
                {
                    if (OnSessionStateChanged != null)
                    {
                        OnSessionStateChanged(LoginStatus.LoggedOut);
                    }
                }

                break;
            }
#else
                {
                    throw new NotImplementedException("WebviewAuthentication is not implemented on Windows Phone");
                }
#endif// WINDOWS

            case FacebookLoginBehavior.LoginBehaviorApplicationOnly:
            {
#if WP8 || WINDOWS_PHONE
                LoginWithApp(permissions);
                break;
#else
                throw new NotImplementedException("Login via app is not available on Windows");
#endif
            }
            }
        }