Пример #1
0
        public async Task <bool> AuthenticateAsync(Constants.EProviderType providerType)
        {
            var success = false;

            try
            {
                // Sign in using a server-managed flow.
                loginuser = await App.CurrentClient.LoginAsync
                            (
                    this,
                    providerType.MobileServiceAuthenticationProvider(),
                    "apochan-scheme",
                    providerType.MobileServiceParameters()
                            );

                if (loginuser != null)
                {
                    UserItem user = new UserItem()
                    {
                        AMSToken = loginuser.MobileServiceAuthenticationToken
                        ,
                        AMSUserId = loginuser.UserId
                        ,
                        ProviderType = providerType.GetHashCode()
                    };

                    // get provider user profile.
                    BaseAuthProvider providerObj = BaseAuthProvider.GetAuthProvider(providerType);
                    string           json        = await providerObj.GetProfileJson(loginuser.MobileServiceAuthenticationToken);

                    providerObj.SetUserProfile(user, json);

                    success = true;
                    await user.SetUserToken();

                    await providerObj.GetUserPicture(user);
                }
            }
            catch (Exception ex)
            {
                string message = ex.Message;
                // Display the success or failure message.
                AlertDialog.Builder builder = new AlertDialog.Builder(this);
                builder.SetMessage(message);
                builder.SetTitle("Sign-in result");
                builder.Create().Show();
            }

            return(success);
        }
Пример #2
0
        public async Task <bool> AuthenticateAsync(Constants.EProviderType providerType)
        {
            var success = false;

            try
            {
                // Sign in using a server-managed flow.
                loginuser = await App.CurrentClient.LoginAsync
                            (
                    UIApplication.SharedApplication.KeyWindow.RootViewController,
                    providerType.MobileServiceAuthenticationProvider(),
                    "apochan-scheme",
                    providerType.MobileServiceParameters()
                            );

                if (loginuser != null)
                {
                    UserItem user = new UserItem()
                    {
                        AMSToken = loginuser.MobileServiceAuthenticationToken
                        ,
                        AMSUserId = loginuser.UserId
                        ,
                        ProviderType = providerType.GetHashCode()
                    };

                    // get provider user profile.
                    BaseAuthProvider providerObj = BaseAuthProvider.GetAuthProvider(providerType);
                    string           json        = await providerObj.GetProfileJson(loginuser.MobileServiceAuthenticationToken);

                    providerObj.SetUserProfile(user, json);

                    success = true;
                    await user.SetUserToken();
                }
            }
            catch (Exception ex)
            {
                string message = ex.Message;
                // Display the success or failure message.
                UIAlertView avAlert = new UIAlertView("Sign-in result", message, null, "OK", null);
                avAlert.Show();
            }

            return(success);
        }