Ejemplo n.º 1
0
        private async Task UpdateMsaUiAsync(bool isMsaValid)
        {
            try
            {
                string nl = Environment.NewLine;

                if (isMsaValid)
                {
                    MsaSignInButtonText = SignOutText;

                    var provider = AppService.AuthManager.GetProvider(ProviderNames.MsaProviderKey);
                    var token    = await provider.GetTokenSilentAsync();

                    if (token != null)
                    {
                        InvokeOnUIThread(async() =>
                        {
                            var bitmap = await LiveApiUtil.GetPictureAsync(token);
                            if (bitmap != null)
                            {
                                MsaBitmap = bitmap;
                            }
                        });

                        var userInfo = await LiveApiUtil.GetUserInfoAsync(token);

                        if (userInfo != null)
                        {
                            MsaInfoText    = userInfo.name;
                            MsaDisplayName = userInfo.name;
                        }

                        IsMsaInfoPanelVisible = true;
                    }
                }
                else
                {
                    MsaSignInButtonText   = SignInText;
                    IsMsaInfoPanelVisible = false;
                }
            }
            catch (Exception ex)
            {
                AppService.LogService.WriteException(ex);
            }
        }
Ejemplo n.º 2
0
        private async void AuthManager_TokenStatusChanged(object sender, TokenStatusEventArgs args)
        {
            App.LogService.Write($"Provider: {args.ProviderKey}, Old: {args.OldValue}, New: {args.NewValue}");

            var  msa        = AuthManager.GetProvider(ProviderNames.MsaProviderKey);
            bool isMsaValid = msa.IsTokenValid();

            LiveUserInfo userInfo = null;

            if (isMsaValid)
            {
                userInfo = await LiveApiUtil.GetUserInfoAsync(await AuthManager.GetProvider(ProviderNames.MsaProviderKey).GetTokenSilentAsync());
            }

            var  aad        = AuthManager.GetGraphProvider();
            bool isAadValid = (aad != null) ? aad.IsTokenValid() : false;

            // Update the UI
            PageService?.SetSignInStatus(isMsaValid, isAadValid, userInfo?.name);
        }