Esempio n. 1
0
        private async void CheckAccounts()
        {
            if (SignedInAccount == null)
            {
                if (authClient == null)
                {
                    authClient = PublicClientApplicationBuilder.Create(Secrets.AUTH_CLIENT_ID).Build();
                }

                var accounts = await authClient.GetAccountsAsync();

                var firstAccount = accounts.FirstOrDefault();
                if (firstAccount != null)
                {
                    Debug.WriteLine($"Account found {firstAccount.Username}");

                    SignedInAccount = firstAccount;

                    if (localSettings.Values.ContainsKey("AccountType"))
                    {
                        var accountType = localSettings.Values["AccountType"] as string;
                        IsMSA = accountType.Equals("MSA");

                        if (apiClient == null)
                        {
                            IReadOnlyList <string> scopes = IsMSA ? MsaScopes : AadScopes;
                            var authResult = await authClient.AcquireTokenSilent(scopes, SignedInAccount).ExecuteAsync();

                            apiClient = new UserNotificationApi(authResult.AccessToken);
                        }
                    }
                }
            }
        }
Esempio n. 2
0
 public void Reset()
 {
     SignedInAccount = null;
     UserNotificationSubscriptionId = null;
     apiClient = null;
     historicalNotifications.Clear();
     localSettings.Values.Clear();
     CacheUpdated?.Invoke(this, new EventArgs());
 }
Esempio n. 3
0
        public async Task <bool> SignInMSA()
        {
            try
            {
                IsMSA      = true;
                authClient = PublicClientApplicationBuilder.Create(Secrets.AUTH_CLIENT_ID)
                             .WithAuthority("https://login.microsoftonline.com/consumers")
                             .WithRedirectUri(Secrets.AUTH_REDIRECT_ID)
                             .Build();
                var authResult = await authClient.AcquireTokenInteractive(MsaScopes).ExecuteAsync();

                Debug.WriteLine($"Sign-in successful for {authResult.Account.Username}, token = {authResult.AccessToken}");
                SignedInAccount = authResult.Account;
                apiClient       = new UserNotificationApi(authResult.AccessToken);
                localSettings.Values["AccountType"] = "MSA";
                return(true);
            }
            catch (Exception error)
            {
                Debug.WriteLine($"Sign-in failed; Error={error.Message}", NotifyType.ErrorMessage);
                return(false);
            }
        }