예제 #1
0
        private async Task ExecuteCreateProfileAsync(UserSignUpInfo signUpInfo, bool retryOnTokenException)
        {
            try
            {
                _connectivityService.CheckConnection();

                await _secretsProvider.InitializeAsync().ConfigureAwait(false);

                var identifier = await _secretsProvider.GetDeviceIdentifierAsync().ConfigureAwait(false);

                var request  = new RegisterRequest(signUpInfo.Username, signUpInfo.Password, identifier);
                var response = await _platformClient.Endpoints.RegisterUserAsync(request).ConfigureAwait(false);

                await _authenticationInfoService.InitUserInfoAsync(response.Metadata, response.UserProfile, response.Token).ConfigureAwait(false);
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "Failed to create user profile.");
                if (!_serviceErrorHandler.TryHandle(ex, out var generatedException))
                {
                    throw;
                }

                if (generatedException is CreateProfileTokenValidationException)
                {
                    await ExecuteCreateProfileAsync(signUpInfo, false);

                    return;
                }

                generatedException.Rethrow();
            }
        }
예제 #2
0
        public async Task SignInAsync(UserCredentials userCredentials)
        {
            try
            {
                _connectivityService.CheckConnection();

                var request  = new LoginRequest(userCredentials.Username, userCredentials.Password);
                var response = await _platformClient.Endpoints.LoginAsync(request).ConfigureAwait(false);

                await _secretsProvider.InitializeAsync(response.UserToken).ConfigureAwait(false);

                await _authenticationInfoService.InitUserInfoAsync(response.Metadata, response.UserProfile, response.Token).ConfigureAwait(false);
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "Failed to sign in.");
                if (_serviceErrorHandler.TryHandle(ex, out var generatedException))
                {
                    generatedException.Rethrow();
                }

                throw;
            }
        }