'How to programmatically authenticate Subscriber and pass in application credentials json for Spring Cloud
I have a Subscriber app in Java using spring-cloud-gcp-starter-pubsub, but I don't want to authenticate to Google Cloud using a JSON file on the filesystem; we are getting the file from a different secure location (not on disk) and want to programmatically authenticate the Subscriber.
Currently our app relies on the standard Spring Cloud magic that automatically authenticates based on the JSON file on disk; we create the Subscriber using the PubSubSubscriberTemplate created by default:
@Bean
public Subscriber subscriber(PubSubSubscriberTemplate template) {
return template.subscribeAndConvert(...);
}
How can we programmatically authenticate the Subscriber, assuming the app has already retrieved the json credentials from a secure external source?
Solution 1:[1]
Provide a bean implementing the CredentialsProvider
interface -- it will be evaluated lazily wherever credentials are needed.
refdoc: https://googlecloudplatform.github.io/spring-cloud-gcp/3.2.1/reference/html/index.html#credentials
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Elena Felder |