0

We are planning to host a topic (pub/sub) on google cloud and have created a topic and client service account.

Now I have to connect to the topic and publish the messages. I was trying to authenticate before publishing the messages. But couldn't find a suitable approach for my scenario "Local Server to Google Cloud authentication using rest API".

Please help me if there is any approach available for this method.

Here is the code I am using but is giving browser redirect response instead of access token. Please find the code below and response

 private static Credential authorize() throws Exception { HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport(); GoogleClientSecrets clientSecrets = JSON_FACTORY.fromReader(new InputStreamReader(new FileInputStream(new File(KEY_FILE_LOCATION))), GoogleClientSecrets.class); if (clientSecrets.getDetails().getClientId().startsWith("Enter") || clientSecrets.getDetails().getClientSecret().startsWith("Enter ")) { System.out.println("Enter Client ID and Secret in client_secrets.json"); System.exit(1); } GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder( httpTransport, JSON_FACTORY, clientSecrets, Collections.singleton(PubsubScopes.PUBSUB)).build(); return new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver()).authorize(SERVICE_ACCOUNT_EMAIL); } Please open the following address in your browser: 

https://accounts.google.com/o/oauth2/auth?client_id=1164246778127&redirect_uri=http://localhost:53869/Callback&response_type=code&scope=https://www.googleapis.com/auth/pubsub

1 Answer 1

1

All you need is the service account's JSON key file. Check out the documentation to see how you can use this (application default credentials using the GOOGLE_APPLICATION_CREDENTIALS environment variable).

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.