Exemplo n.º 1
0
        public async Task <IUserInfo> GetUserInfo()
        {
            _logger.Method().Start();

            AccountData acData = _accountRepository.AccountData;

            Union3 <UserInfo, LoginErrorDto, Exception> loginResult;

            if (!string.IsNullOrWhiteSpace(acData?.OauthToken) && !string.IsNullOrWhiteSpace(acData.XToken))
            {
                loginResult = await _internalAuthService.GetUserInfo(acData.OauthToken, acData.XToken);
            }
            else if (!string.IsNullOrWhiteSpace(acData?.XToken))
            {
                loginResult = await _internalAuthService.LoginWithXToken(acData.XToken);
            }
            else
            {
                return((null as IUserInfo).RetWithLog(_logger).Log());
            }

            return(loginResult.Match(ui =>
            {
                ProcessUserInfo(ui);
                return ui;
            },
                                     _ => null,
                                     _ => null).RetWithLog(_logger).Log());
        }
Exemplo n.º 2
0
        private async Task TryGetToken(TokenListener tokenListener)
        {
            _loginTask = _loginTask ?? _internalAuthService.LoginWithXToken(_userInfo.Xtoken);

            Union3 <UserInfo, LoginErrorDto, Exception> loginResult = await _loginTask;

            loginResult.Match(userInfo =>
            {
                _userInfo.Token = userInfo.Token;
                _userInfo.Uid   = userInfo.Uid;
                tokenListener.OnTokenReceived(_userInfo.Token);
            },
                              error =>
            {
                tokenListener.OnTokenRefreshFailed(error.Error);
                AppAnalytics.Instance.TrackError(error.ErrorDescription);
            },
                              ex =>
            {
                tokenListener.OnTokenRefreshFailed(ex.Message);
                AppAnalytics.Instance.TrackError(ex);
            });

            _loginTask = null;
        }