mirror of
https://github.com/FoggedLens/deflock-app.git
synced 2026-08-15 23:50:49 +02:00
This it the right way to do client IDs / secrets and local builds
This commit is contained in:
@@ -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');
|
||||
}
|
||||
@@ -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');
|
||||
}
|
||||
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user