Skip to content

Commit

Permalink
Merge pull request #2071 from UCSD/dotenv_issue_2021
Browse files Browse the repository at this point in the history
Integrate package flutter_dotenv for #2021
  • Loading branch information
c3bryant authored Sep 10, 2024
2 parents 4786d9d + bcc6bd4 commit 1eb5dcc
Show file tree
Hide file tree
Showing 38 changed files with 238 additions and 535 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
.buildlog/
.history
.svn/
*.env

# IntelliJ related
*.iml
Expand Down Expand Up @@ -51,6 +52,7 @@ android/.project
android/app/.classpath
android/app/.project
android/app/.settings/
android/app/google-services.json

# iOS/XCode related
**/ios/**/*.mode1v3
Expand Down
17 changes: 0 additions & 17 deletions android/.project

This file was deleted.

48 changes: 0 additions & 48 deletions android/app/google-services.json

This file was deleted.

84 changes: 0 additions & 84 deletions android/gradlew.bat

This file was deleted.

6 changes: 0 additions & 6 deletions assets/public_key.txt

This file was deleted.

31 changes: 1 addition & 30 deletions ios/Runner/GoogleService-Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,6 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CLIENT_ID</key>
<string>204227644417-badlapi7e50isd0bsghdtcl6k3o1d7u5.apps.googleusercontent.com</string>
<key>REVERSED_CLIENT_ID</key>
<string>com.googleusercontent.apps.204227644417-badlapi7e50isd0bsghdtcl6k3o1d7u5</string>
<key>API_KEY</key>
<string>AIzaSyDWEx4YhK8RcoiBizBCymKVAjahP0LCmcU</string>
<key>GCM_SENDER_ID</key>
<string>204227644417</string>
<key>PLIST_VERSION</key>
<string>1</string>
<key>BUNDLE_ID</key>
<string>edu.ucsd.ucsandiego</string>
<key>PROJECT_ID</key>
<string>uc-san-diego-qa</string>
<key>STORAGE_BUCKET</key>
<string>uc-san-diego-qa.appspot.com</string>
<key>IS_ADS_ENABLED</key>
<false></false>
<key>IS_ANALYTICS_ENABLED</key>
<false></false>
<key>IS_APPINVITE_ENABLED</key>
<true></true>
<key>IS_GCM_ENABLED</key>
<true></true>
<key>IS_SIGNIN_ENABLED</key>
<true></true>
<key>GOOGLE_APP_ID</key>
<string>1:204227644417:ios:cd9429451b823426</string>
<key>DATABASE_URL</key>
<string>https://uc-san-diego-qa.firebaseio.com</string>

</dict>
</plist>
4 changes: 2 additions & 2 deletions ios/Runner/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>$(MARKETING_VERSION)</string>
<string>$(FLUTTER_BUILD_NAME)</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleURLTypes</key>
Expand All @@ -42,7 +42,7 @@
</dict>
</array>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<string>$(FLUTTER_BUILD_NUMBER)</string>
<key>ITSAppUsesNonExemptEncryption</key>
<false/>
<key>LSApplicationCategoryType</key>
Expand Down
20 changes: 19 additions & 1 deletion lib/app_networking.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import 'dart:async';
import 'dart:ffi';

import 'package:campus_mobile_experimental/app_constants.dart';
import 'package:campus_mobile_experimental/app_styles.dart';
import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:flutter_dotenv/flutter_dotenv.dart';

class NetworkHelper {
///TODO: inside each service that file place a switch statement to handle all
Expand All @@ -14,7 +16,7 @@ class NetworkHelper {
static const int SSO_REFRESH_MAX_RETRIES = 3;
static const int SSO_REFRESH_RETRY_INCREMENT = 5000;
static const int SSO_REFRESH_RETRY_MULTIPLIER = 3;
static const int DEFAULT_TIMEOUT = 60000;
static final int DEFAULT_TIMEOUT = int.parse(dotenv.get('DEFAULT_TIMEOUT'));

Future<dynamic> fetchData(String url) async {
Dio dio = new Dio();
Expand Down Expand Up @@ -193,4 +195,20 @@ class NetworkHelper {
return null;
}
}

Future<bool> getNewToken(Map<String, String> headers) async {
final String tokenEndpoint = dotenv.get('NEW_TOKEN_ENDPOINT');
final Map<String, String> tokenHeaders = {
"content-type": 'application/x-www-form-urlencoded',
"Authorization": dotenv.get('MOBILE_APP_PUBLIC_DATA_KEY')
};
try {
var response = await authorizedPost(
tokenEndpoint, tokenHeaders, "grant_type=client_credentials");
headers["Authorization"] = "Bearer " + response["access_token"];
return true;
} catch (e) {
return false;
}
}
}
5 changes: 3 additions & 2 deletions lib/core/providers/scanner.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:campus_mobile_experimental/app_constants.dart';
import 'package:campus_mobile_experimental/core/providers/user.dart';
import 'package:campus_mobile_experimental/core/services/barcode.dart';
import 'package:flutter/material.dart';
import 'package:flutter_dotenv/flutter_dotenv.dart';
import 'package:flutter_scandit_plugin/flutter_scandit_plugin.dart';
import 'package:permission_handler/permission_handler.dart';

Expand Down Expand Up @@ -37,9 +38,9 @@ class ScannerDataProvider extends ChangeNotifier {

void initState() {
if (Platform.isIOS) {
_licenseKey = 'SCANDIT_NATIVE_LICENSE_IOS_PH';
_licenseKey = dotenv.get('SCANDIT_NATIVE_LICENSE_IOS');
} else if (Platform.isAndroid) {
_licenseKey = 'SCANDIT_NATIVE_LICENSE_ANDROID_PH';
_licenseKey = dotenv.get('SCANDIT_NATIVE_LICENSE_ANDROID');
}

errorText = "Something went wrong, please try again.";
Expand Down
9 changes: 2 additions & 7 deletions lib/core/providers/user.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import 'package:campus_mobile_experimental/core/services/user.dart';
import 'package:encrypt/encrypt.dart';
import 'package:firebase_analytics/firebase_analytics.dart';
import 'package:flutter/material.dart';
import 'package:flutter_dotenv/flutter_dotenv.dart';
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import 'package:hive/hive.dart';
import 'package:pointycastle/asymmetric/api.dart';
Expand Down Expand Up @@ -146,13 +147,7 @@ class UserDataProvider extends ChangeNotifier {

/// Encrypt given username and password and store on device
void _encryptAndSaveCredentials(String username, String password) {
// TODO: import assets/public_key.txt
final String pkString = '-----BEGIN PUBLIC KEY-----\n' +
'MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDJD70ejMwsmes6ckmxkNFgKley\n' +
'gfN/OmwwPSZcpB/f5IdTUy2gzPxZ/iugsToE+yQ+ob4evmFWhtRjNUXY+lkKUXdi\n' +
'hqGFS5sSnu19JYhIxeYj3tGyf0Ms+I0lu/MdRLuTMdBRbCkD3kTJmTqACq+MzQ9G\n' +
'CaCUGqS6FN1nNKARGwIDAQAB\n' +
'-----END PUBLIC KEY-----';
final String pkString = dotenv.get('USER_CREDENTIALS_PUBLIC_KEY');

final rsaParser = RSAKeyParser();
final pc.RSAPublicKey publicKey = rsaParser.parse(pkString) as RSAPublicKey;
Expand Down
13 changes: 5 additions & 8 deletions lib/core/services/authentication.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:campus_mobile_experimental/app_networking.dart';
import 'package:campus_mobile_experimental/core/models/authentication.dart';
import 'package:flutter_dotenv/flutter_dotenv.dart';

class AuthenticationService {
AuthenticationService();
Expand All @@ -12,22 +13,18 @@ class AuthenticationService {
final NetworkHelper _networkHelper = NetworkHelper();

final String authServiceApiUrl =
"https://uokdbiyx00.execute-api.us-west-2.amazonaws.com/qa/v1.1/access-profile";
final String authServiceApiKey = 'uRgcQKJKMW4WzC2scgUXUjbE7e8TQJN7JsfjVBK6';

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

/// fetch data
/// MODIFIED TO USE EXPONENTIAL RETRY
var response = await _networkHelper.authorizedPublicPost(
authServiceApiUrl, authServiceHeaders, null);
dotenv.get('AUTH_SERVICE_API_ENDPOINT'), authServiceHeaders, null);

/// check to see if response has an error
if (response['errorMessage'] != null) {
Expand All @@ -50,14 +47,14 @@ class AuthenticationService {
_error = null;
try {
final Map<String, String> authServiceHeaders = {
'x-api-key': authServiceApiKey,
'x-api-key': dotenv.get('AUTH_SERVICE_API_KEY'),
'Authorization': base64EncodedWithEncryptedPassword,
};

/// fetch data
/// MODIFIED TO USE EXPONENTIAL RETRY
var response = await _networkHelper.authorizedPost(
authServiceApiUrl, authServiceHeaders, null);
dotenv.get('AUTH_SERVICE_API_ENDPOINT'), authServiceHeaders, null);

/// check to see if response has an error
if (response['errorMessage'] != null) {
Expand Down
6 changes: 3 additions & 3 deletions lib/core/services/availability.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'dart:async';

import 'package:campus_mobile_experimental/app_networking.dart';
import 'package:campus_mobile_experimental/core/models/availability.dart';
import 'package:flutter_dotenv/flutter_dotenv.dart';

class AvailabilityService {
AvailabilityService();
Expand All @@ -22,9 +23,8 @@ class AvailabilityService {
try {
/// fetch data
String _response = await (_networkHelper.authorizedFetch(
"https://api-qa.ucsd.edu:8243/campusbusyness/v1/busyness", {
"Authorization":
"Basic djJlNEpYa0NJUHZ5akFWT0VRXzRqZmZUdDkwYTp2emNBZGFzZWpmaWZiUDc2VUJjNDNNVDExclVh"
dotenv.get('AVAILABILITY_API_ENDPOINT'), {
"Authorization": dotenv.get('MOBILE_APP_PUBLIC_DATA_KEY')
}));

/// parse data
Expand Down
Loading

0 comments on commit 1eb5dcc

Please sign in to comment.