Beispiel #1
0
        public async Task <RegistrationResultModel> GoogleRegisterAsync(GoogleRegistrationRequestDto model)
        {
            var authorization = $"Bearer {model.AccessToken}";

            GoogleUser user;

            try
            {
                user = await _googleApiClient.GetGoogleUser(authorization);
            }
            catch (ApiException e)
            {
                if (e.StatusCode == HttpStatusCode.Unauthorized)
                {
                    return(new RegistrationResultModel
                    {
                        Error = CustomerError.InvalidOrExpiredGoogleAccessToken
                    });
                }

                throw;
            }

            var result = await _customerManagementServiceClient.CustomersApi.RegisterAsync(new RegistrationRequestModel
            {
                LoginProvider = LoginProvider.Google,
                Email         = user.Email,
                ReferralCode  = model.ReferralCode,
                FirstName     = model.FirstName,
                LastName      = model.LastName
            });

            return(_mapper.Map <RegistrationResultModel>(result));
        }
        public async Task <AuthenticationResultModel> GoogleAuthenticateAsync(string accessToken)
        {
            var authorization = $"Bearer {accessToken}";

            GoogleUser user;

            try
            {
                user = await _googleApiClient.GetGoogleUser(authorization);
            }
            catch (ApiException e)
            {
                if (e.StatusCode == HttpStatusCode.Unauthorized)
                {
                    return(new AuthenticationResultModel
                    {
                        Error = CustomerError.InvalidOrExpiredGoogleAccessToken
                    });
                }

                throw;
            }

            var result = await _customerManagementServiceClient.AuthApi.AuthenticateAsync(new AuthenticateRequestModel
            {
                Email         = user.Email,
                LoginProvider = LoginProvider.Google
            });

            return(_mapper.Map <AuthenticationResultModel>(result));
        }