From 6a2c1230d23c81901c57c34df7b4de2513ec7739 Mon Sep 17 00:00:00 2001 From: stopflock Date: Thu, 9 Oct 2025 11:15:21 -0500 Subject: [PATCH] This it the right way to do client IDs / secrets and local builds --- .github/workflows/workflow.yml | 15 +++----------- .gitignore | 2 +- lib/keys.dart | 36 ++++++++++++++++++++++++++++++++++ lib/keys.dart.example | 33 ------------------------------- lib/keys.properties.example | 10 ++++++++++ pubspec.yaml | 2 +- 6 files changed, 51 insertions(+), 47 deletions(-) create mode 100644 lib/keys.dart delete mode 100644 lib/keys.dart.example create mode 100644 lib/keys.properties.example diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 0df61ee..23ed2fe 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -47,9 +47,6 @@ jobs: with: channel: 'stable' - - name: Create keys.dart from example - run: cp lib/keys.dart.example lib/keys.dart - - name: Install dependencies run: flutter pub get @@ -70,7 +67,7 @@ jobs: echo "storeFile=keystore.jks" >> android/key.properties - name: Build Android .apk - run: flutter build apk --release + run: flutter build apk --release --dart-define=OSM_PROD_CLIENTID='${{ secrets.OSM_PROD_CLIENTID }}' --dart-define=OSM_SANDBOX_CLIENTID='${{ secrets.OSM_SANDBOX_CLIENTID }}' - name: Upload .apk artifact uses: actions/upload-artifact@v4 @@ -99,9 +96,6 @@ jobs: with: channel: 'stable' - - name: Create keys.dart from example - run: cp lib/keys.dart.example lib/keys.dart - - name: Install dependencies run: flutter pub get @@ -122,7 +116,7 @@ jobs: echo "storeFile=keystore.jks" >> android/key.properties - name: Build Android appBundle - run: flutter build appbundle + run: flutter build appbundle --dart-define=OSM_PROD_CLIENTID='${{ secrets.OSM_PROD_CLIENTID }}' --dart-define=OSM_SANDBOX_CLIENTID='${{ secrets.OSM_SANDBOX_CLIENTID }}' - name: Upload .aab artifact uses: actions/upload-artifact@v4 @@ -144,9 +138,6 @@ jobs: with: channel: 'stable' - - name: Create keys.dart from example - run: cp lib/keys.dart.example lib/keys.dart - - name: Install dependencies run: flutter pub get @@ -160,7 +151,7 @@ jobs: - name: Build iOS .app run: | - flutter build ios --release --no-codesign + flutter build ios --release --no-codesign --dart-define=OSM_PROD_CLIENTID='${{ secrets.OSM_PROD_CLIENTID }}' --dart-define=OSM_SANDBOX_CLIENTID='${{ secrets.OSM_SANDBOX_CLIENTID }}' ./app2ipa.sh build/ios/iphoneos/Runner.app - name: Upload IPA artifact diff --git a/.gitignore b/.gitignore index 848d5d8..c97d948 100644 --- a/.gitignore +++ b/.gitignore @@ -92,7 +92,7 @@ Thumbs.db # Secrets or signing keys (add if used) *.keystore .env -lib/keys.dart +lib/keys.properties # ─────────────────────────────── # For now - not targeting these diff --git a/lib/keys.dart b/lib/keys.dart new file mode 100644 index 0000000..ad4709e --- /dev/null +++ b/lib/keys.dart @@ -0,0 +1,36 @@ +// OpenStreetMap OAuth client IDs for this app. + +import 'dart:io'; + +String _readFromProperties(String key) { + final file = File('lib/keys.properties'); + if (!file.existsSync()) return ''; + + final lines = file.readAsLinesSync(); + for (final line in lines) { + if (line.startsWith(key + '=')) { + return line.substring(key.length + 1); + } + } + return ''; +} + +String get kOsmProdClientId { + const fromBuild = String.fromEnvironment('OSM_PROD_CLIENTID'); + if (fromBuild.isNotEmpty) return fromBuild; + + final fromFile = _readFromProperties('OSM_PROD_CLIENTID'); + if (fromFile.isNotEmpty) return fromFile; + + throw Exception('OSM_PROD_CLIENTID not configured'); +} + +String get kOsmSandboxClientId { + const fromBuild = String.fromEnvironment('OSM_SANDBOX_CLIENTID'); + if (fromBuild.isNotEmpty) return fromBuild; + + final fromFile = _readFromProperties('OSM_SANDBOX_CLIENTID'); + if (fromFile.isNotEmpty) return fromFile; + + throw Exception('OSM_SANDBOX_CLIENTID not configured'); +} \ No newline at end of file diff --git a/lib/keys.dart.example b/lib/keys.dart.example deleted file mode 100644 index 2f9445d..0000000 --- a/lib/keys.dart.example +++ /dev/null @@ -1,33 +0,0 @@ -// OpenStreetMap OAuth client IDs for this app. -// -// NEVER commit keys.dart to public repos. For open source, use keys.dart.example instead. - -import 'dart:io'; - -// Fallback client IDs for local development - replace with your own if building locally -const String _kOsmProdClientIdFallback = ''; // Put your fallback production client ID here -const String _kOsmSandboxClientIdFallback = ''; // Put your fallback sandbox client ID here - -// Get client IDs from environment variables first, then fallback to constants -String get kOsmProdClientId { - final envValue = Platform.environment['OSM_PROD_CLIENTID']; - if (envValue != null && envValue.isNotEmpty) { - return envValue; - } - if (_kOsmProdClientIdFallback.isNotEmpty) { - return _kOsmProdClientIdFallback; - } - throw Exception('OSM Production Client ID not configured. Set OSM_PROD_CLIENTID environment variable or configure fallback in keys.dart'); -} - -String get kOsmSandboxClientId { - final envValue = Platform.environment['OSM_SANDBOX_CLIENTID']; - if (envValue != null && envValue.isNotEmpty) { - return envValue; - } - if (_kOsmSandboxClientIdFallback.isNotEmpty) { - return _kOsmSandboxClientIdFallback; - } - throw Exception('OSM Sandbox Client ID not configured. Set OSM_SANDBOX_CLIENTID environment variable or configure fallback in keys.dart'); -} - diff --git a/lib/keys.properties.example b/lib/keys.properties.example new file mode 100644 index 0000000..9c523b0 --- /dev/null +++ b/lib/keys.properties.example @@ -0,0 +1,10 @@ +# OpenStreetMap OAuth Client IDs +# Copy this file to keys.properties and fill in your values for local development +# These are used as fallback when environment variables are not provided via --dart-define. +# +# Get your client IDs from: +# Production: https://www.openstreetmap.org/oauth2/applications +# Sandbox: https://master.apis.dev.openstreetmap.org/oauth2/applications + +OSM_PROD_CLIENTID=your_production_client_id_here +OSM_SANDBOX_CLIENTID=your_sandbox_client_id_here \ No newline at end of file diff --git a/pubspec.yaml b/pubspec.yaml index ea3466c..30cbbf8 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,7 +1,7 @@ name: deflockapp description: Map public surveillance infrastructure with OpenStreetMap publish_to: "none" -version: 1.2.1+3 # The thing after the + is the google versionCode +version: 1.2.2+3 # The thing after the + is the google versionCode environment: sdk: ">=3.5.0 <4.0.0" # oauth2_client 4.x needs Dart 3.5+