<commit_before>import 'package:campus_mobile_experimental/core/models/authentication_model.dart';
import 'package:campus_mobile_experimental/core/services/networking.dart';
import 'dart:convert';

import 'package:flutter_secure_storage/flutter_secure_storage.dart';

class AuthenticationService {
  AuthenticationService();
  String _error;
  AuthenticationModel _data;
  DateTime _lastUpdated;

  /// add state related things for view model here
  /// add any type of data manipulation here so it can be accessed via provider

  final NetworkHelper _networkHelper = NetworkHelper();
  final String endpoint =
      "https://3hepzvdimd.execute-api.us-west-2.amazonaws.com/dev/v1/access-profile";
  final String AUTH_SERVICE_API_KEY =
      '<KEY>';

  final String refreshTokenEndpoint =
      'https://3hepzvdimd.execute-api.us-west-2.amazonaws.com/dev/v1/access-profile/refresh';

  Future<bool> login(String base64EncodedWithEncryptedPassword) async {
    _error = null;
    try {
      final Map<String, String> authServiceHeaders = {
        'x-api-key': AUTH_SERVICE_API_KEY,
        'Authorization': base64EncodedWithEncryptedPassword,
      };

      /// fetch data
      var response = await _networkHelper.authorizedPost(
          endpoint, authServiceHeaders, null);

      /// parse data
      final authenticationModel = AuthenticationModel.fromJson(response);
      _data = authenticationModel;
      _lastUpdated = DateTime.now();
      return true;
    } catch (e) {
      ///TODO: handle errors thrown by the network class for different types of error responses
      _error = e.toString();
      print("authentication error:" + _error);
      return false;
    }
  }

  Future<bool> refreshAccessToken(String refreshToken) async {
    _error = null;
    //TODO: upload consumer secret and key to lambda or remote config and remove from code here
    final tokenHeaders = {'refreshToken': refreshToken};
    try {
      var response = await _networkHelper.authorizedPost(
          refreshTokenEndpoint, tokenHeaders, null);
      if (response['error'] != null) {
        throw (response['error']);
      }
      final authenticationModel = AuthenticationModel.fromJson(response);
      _data = authenticationModel;
      return true;
    } catch (e) {
      ///TODO: check to see if error returned means the refresh token is expired
      ///if refresh token is expired then try to reauthenticate using login method
      _error = e.toString();
      return false;<commit_msg>fix typo and update auth service lastUpdated time stamp on refresh token<commit_after>import 'package:campus_mobile_experimental/core/models/authentication_model.dart';
import 'package:campus_mobile_experimental/core/services/networking.dart';
import 'dart:convert';

import 'package:flutter_secure_storage/flutter_secure_storage.dart';

class AuthenticationService {
  AuthenticationService();
  String _error;
  AuthenticationModel _data;
  DateTime _lastUpdated;

  /// add state related things for view model here
  /// add any type of data manipulation here so it can be accessed via provider

  final NetworkHelper _networkHelper = NetworkHelper();
  final String endpoint =
      "https://3hepzvdimd.execute-api.us-west-2.amazonaws.com/dev/v1/access-profile";
  final String AUTH_SERVICE_API_KEY =
      '<KEY>';

  final String refreshTokenEndpoint =
      'https://3hepzvdimd.execute-api.us-west-2.amazonaws.com/dev/v1/access-profile/refresh';

  Future<bool> login(String base64EncodedWithEncryptedPassword) async {
    _error = null;
    try {
      final Map<String, String> authServiceHeaders = {
        'x-api-key': AUTH_SERVICE_API_KEY,
        'Authorization': base64EncodedWithEncryptedPassword,
      };

      /// fetch data
      var response = await _networkHelper.authorizedPost(
          endpoint, authServiceHeaders, null);

      /// parse data
      final authenticationModel = AuthenticationModel.fromJson(response);
      _data = authenticationModel;
      _lastUpdated = DateTime.now();
      return true;
    } catch (e) {
      ///TODO: handle errors thrown by the network class for different types of error responses
      _error = e.toString();
      print("authentication error:" + _error);
      return false;
    }
  }

  Future<bool> refreshAccessToken(String refreshToken) async {
    _error = null;
    final tokenHeaders = {'refresh_token': refreshToken};
    try {
      var response = await _networkHelper.authorizedPost(
          refreshTokenEndpoint, tokenHeaders, null);
      if (response['error'] != null) {
        throw (response['error']);
      }
      final authenticationModel = AuthenticationModel.fromJson(response);
      _data = authenticationModel;
      _lastUpdated = DateTime.now();
      return true;
    } catch (e) {
      ///TODO: check to see if error returned means the refresh token is expired
      ///if refresh token is expired then try to reauthenticate using login method
      _error = e.toString();
      return false;
{'fraction_non_alphanumeric': 0.09256661991584852, 'fraction_numerical': 0.004007212983370066, 'mean_word_length': 3.4021164021164023, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '968732', 'n_tokens_mistral': 1364, 'n_tokens_neox': 1336, 'n_words': 376}