I'm using Spring boot 2.7 and firebase-admin 7.1.0 dependency. I need to create a Firestore bean using Firestore credentials. I didn't find any way to set credentials using application.properties or by setting the environment variables. The only way I found was to get credentials using a .json file. I feel this is not secure.
@Value("${firebase.credential.path}")
private String credentialPath;
@Bean
public Firestore getFireStore() throws IOException {
FileInputStream serviceAccount = null;
try {
serviceAccount = new FileInputStream(credentialPath);
var credentials = GoogleCredentials.fromStream(serviceAccount);
var options = FirestoreOptions.newBuilder()
.setCredentials(credentials).build();
return options.getService();
} catch (IOException e) {
log.error("Error in firebase authentication bean: {}", e.getMessage());
return null;
}
}
Is there any way to set credentials in the application.properties file or use environment variables if not Is it secure to take credentials from a separate .json file?