コード例 #1
0
        public static Dictionary <string, string> MobileServiceParameters(this Constants.EProviderType providerType)
        {
            switch (providerType)
            {
            case Constants.EProviderType.Google:
                return(new Dictionary <string, string>()
                {
                    { "access_type", "offline" }
                });

            case Constants.EProviderType.Microsoft:
                return(new Dictionary <string, string>()
                {
                    { "resource", "https://graph.microsoft.com" },
                });

            case Constants.EProviderType.Office365:
                return(new Dictionary <string, string>()
                {
                    { "resource", "https://graph.microsoft.com" },
                    { "response_type", "code id_token" }
                });
            }
            return(new Dictionary <string, string>()
            {
                { "resource", "https://graph.microsoft.com" },
            });
        }
コード例 #2
0
        public static BaseAuthProvider GetAuthProvider(Constants.EProviderType providerType)
        {
            switch (providerType)
            {
            case Constants.EProviderType.Google:
                return(new Google());

            case Constants.EProviderType.Office365:
                return(new ActiveDirectory());
            }
            return(new ActiveDirectory());
        }
コード例 #3
0
ファイル: MainActivity.cs プロジェクト: msraom/APO-Chan
        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);
        }
コード例 #4
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);
        }
コード例 #5
0
        public static MobileServiceAuthenticationProvider MobileServiceAuthenticationProvider(this Constants.EProviderType providerType)
        {
            switch (providerType)
            {
            case Constants.EProviderType.Google:
                return(Microsoft.WindowsAzure.MobileServices.MobileServiceAuthenticationProvider.Google);

            case Constants.EProviderType.Microsoft:
                return(Microsoft.WindowsAzure.MobileServices.MobileServiceAuthenticationProvider.MicrosoftAccount);

            case Constants.EProviderType.Office365:
                return(Microsoft.WindowsAzure.MobileServices.MobileServiceAuthenticationProvider.WindowsAzureActiveDirectory);
            }
            return(Microsoft.WindowsAzure.MobileServices.MobileServiceAuthenticationProvider.WindowsAzureActiveDirectory);
        }