示例#1
0
        async void OnFacebookAuthCompleted(object sender, AuthenticatorCompletedEventArgs e)
        {
            var authenticator = sender as OAuth2Authenticator;

            if (authenticator != null)
            {
                authenticator.Completed -= OnFacebookAuthCompleted;
                authenticator.Error     -= OnFacebookAuthError;
            }

            User user = null;

            if (e.IsAuthenticated)
            {
                var request  = new OAuth2Request("GET", new Uri(Constants.UserInfoUrl), null, e.Account);
                var response = await request.GetResponseAsync();

                if (response != null)
                {
                    // Deserialize the data and store it in the account store
                    // The users email address will be used to identify data in SimpleDB
                    string userJson = await response.GetResponseTextAsync();

                    user = JsonConvert.DeserializeObject <User>(userJson);
                }

                if (account != null)
                {
                    await SecureStorageAccountStore.SaveAsync(account, Constants.AppName);
                }

                await DisplayAlert("Email address", user.Email, "OK");
            }
        }
示例#2
0
        void OnFacebookLoginClicked(object sender, EventArgs e)
        {
            string clientId    = Constants.clientId;
            string redirectUri = Constants.redirectUrl;

            account = SecureStorageAccountStore.FindAccountsForServiceAsync(Constants.AppName).Result.FirstOrDefault();

            var authenticator = new OAuth2Authenticator(
                clientId: clientId,
                scope: Constants.scope,
                authorizeUrl: new Uri(Constants.authorizationUrl),
                redirectUrl: new Uri(redirectUri));

            authenticator.Completed += OnFacebookAuthCompleted;
            authenticator.Error     += OnFacebookAuthError;

            AuthenticationState.Authenticator = authenticator;

            var presenter = new Xamarin.Auth.Presenters.OAuthLoginPresenter();

            presenter.Login(authenticator);
        }
示例#3
0
 async void OnClearLoginClicked(object sender, EventArgs e)
 {
     await SecureStorageAccountStore.DeleteAsync(Constants.AppName);
 }