示例#1
0
        public static async Task <Tuple <string, bool, string> > TrySignOutUser(string oneDriveInfoText)
        {
            string ResultText, OneDriveInfoText;
            bool   IsUserSignedOut;
            IEnumerable <IAccount> accounts = await MSGraphQueriesHelper.GetMSGraphAccouts();

            if (accounts == null)
            {
                throw new Exception("No user found!");
            }
            IAccount firstAccount = accounts.FirstOrDefault();

            try
            {
                await MSGraphQueriesHelper.SingOutMSGraphAccount(firstAccount).ConfigureAwait(false);

                string message = LocalizationHelper.GetLocalizedStrings("normalSignOut");
                IsUserSignedOut = false;
                ResultText      = UserSignedOutNormal;
                Trace.WriteLine("From ImageViewModel");

                OneDriveInfoText = EmptyOneDrive;



                return(Tuple.Create(ResultText, IsUserSignedOut, OneDriveInfoText));
            }
            catch (MsalException ex)
            {
                Trace.WriteLine(ex.ToString());
                IsUserSignedOut = true;
                ResultText      = $"Error signing-out user: {ex.Message}";
                return(Tuple.Create(ResultText, IsUserSignedOut, oneDriveInfoText));
            }
        }
示例#2
0
        public static async Task <Tuple <string, bool> > TrySignInUser()
        {
            bool   IsUserSignedOut;
            string ResultText;

            try
            {
                // Sign-in user using MSAL and obtain an access token for MS Graph
                GraphServiceClient graphClient = await MSGraphQueriesHelper.SignInAndInitializeGraphServiceClient();

                // Call the /me endpoint of Graph
                User graphUser = await graphClient.Me.Request().GetAsync();

                ResultText      = "Display Name: " + graphUser.UserPrincipalName + "\nid: " + graphUser.Id;
                IsUserSignedOut = true;
                return(Tuple.Create(ResultText, IsUserSignedOut));
            }
            catch (MsalException msalEx)
            {
                Trace.WriteLine($"Error Acquiring Token:{Environment.NewLine}{msalEx}");
                ResultText      = $"Error Acquiring Token:{Environment.NewLine}{msalEx}";
                IsUserSignedOut = false;
                return(Tuple.Create(ResultText, IsUserSignedOut));
            }
            catch (Exception ex)
            {
                Trace.WriteLine($"Error Acquiring Token Silently:{Environment.NewLine}{ex}");
                ResultText      = $"Error Acquiring Token Silently:{Environment.NewLine}{ex}";
                IsUserSignedOut = false;
                return(Tuple.Create(ResultText, IsUserSignedOut));
            }
        }