I am using googleapis services in my flutter app which requires some credentials in JSON format. What is the best way to store this credentials in my App?
Can I keep a JSON file in my asset folder and read it in my main function?
Or should I hardcode the credentials in my main function? I'm new to flutter development.
My code looks like the following
import 'package:googleapis/storage/v1.dart';
import 'package:googleapis_auth/auth_io.dart';
final _credentials = new ServiceAccountCredentials.fromJson(r'''
{
"private_key_id": ...,
"private_key": ...,
"client_email": ...,
"client_id": ...,
"type": "service_account"
}
''');
const _SCOPES = const [StorageApi.DevstorageReadOnlyScope];
void main() {
clientViaServiceAccount(_credentials, _SCOPES).then((http_client) {
var storage = new StorageApi(http_client);
storage.buckets.list('dart-on-cloud').then((buckets) {
print("Received ${buckets.items.length} bucket names:");
for (var file in buckets.items) {
print(file.name);
}
});
});
}
Where I should keep the following credentials:
{
"private_key_id": ...,
"private_key": ...,
"client_email": ...,
"client_id": ...,
"type": "service_account"
}
I don't think hardcoding like above is a good idea.
I think this should work:https://medium.com/@sokrato/storing-your-secret-keys-in-flutter-c0b9af1c0f69
Thanks.