Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Firebase Cloud Messaging (FCM) Access Token Issue #917

Closed
mostafamahmoud2015 opened this issue Dec 16, 2019 · 10 comments
Closed

Firebase Cloud Messaging (FCM) Access Token Issue #917

mostafamahmoud2015 opened this issue Dec 16, 2019 · 10 comments
Assignees
Labels
needs more info This issue needs more information from the customer to proceed. type: question Request for information or clarification. Not an issue.

Comments

@mostafamahmoud2015
Copy link

mostafamahmoud2015 commented Dec 16, 2019

Hello,

i'm trying to send message via Firebase Cloud Messaging but i received the below error so can you please help in fixing this issue

java.util.concurrent.ExecutionException: com.google.firebase.messaging.FirebaseMessagingException: Error while calling FCM backend service
..

Caused by: java.io.IOException: Error getting access token for service account: connect timed out

code snippets :-
FileInputStream serviceAccount =
new FileInputStream("serviceAccountKey.json");

			FirebaseOptions options = new FirebaseOptions.Builder()
			  .setCredentials(GoogleCredentials.fromStream(serviceAccount))
			  .setDatabaseUrl("https://testnf-42343.firebaseio.com")
			  .build();

	FirebaseApp defaultApp =FirebaseApp.initializeApp(options);
	System.err.println(defaultApp.getName());
	
	UUID uuid = UUID.randomUUID();

	String registrationToken = FirebaseAuth.getInstance().createCustomToken(uuid.toString());


	// See documentation on defining a message payload.
	Message message = Message.builder()
	    .putData("score", "850")
	    .putData("time", "2:45")
	    .setToken(registrationToken)
	    .build();

	// Send a message to the device corresponding to the provided
	// registration token.
	FirebaseMessaging instance = FirebaseMessaging.getInstance();
	String response;
	try {
		response = instance.sendAsync(message).get();

// response = instance.send(message);
// Response is a message ID string.
System.out.println("Successfully sent message: " + response);
} catch (Exception e) {
e.printStackTrace();
}

@yoshi-automation yoshi-automation added the triage me I really want to be triaged. label Dec 17, 2019
@codyoss codyoss added type: question Request for information or clarification. Not an issue. and removed triage me I really want to be triaged. labels Dec 17, 2019
@codyoss
Copy link
Member

codyoss commented Dec 17, 2019

To me this sounds like a firewall issue with the timeout. Can you run curl -I "https://oauth2.googleapis.com/token" from where ever your code is running?

@codyoss codyoss added the needs more info This issue needs more information from the customer to proceed. label Dec 17, 2019
@mostafamahmoud2015
Copy link
Author

mostafamahmoud2015 commented Dec 18, 2019 via email

@codyoss
Copy link
Member

codyoss commented Jan 2, 2020

Yes that is correct, although Firebase does have its own auth as well: https://firebase.google.com/docs/auth Are you still having issues?

@mostafamahmoud2015
Copy link
Author

mostafamahmoud2015 commented Jan 3, 2020 via email

@codyoss codyoss closed this as completed Jan 3, 2020
@kswillian
Copy link

hy guys!

I'm trying to notify my app using the FCM but when i send the request i'm surprised by an exception.

My send code:

`
try{

        Message message = Message.builder()
                .putData("test", "test")
                .putData("test", "test")
                //.setToken("dla3GnhWQjc:APA91bH3dE2St0dLPMmhhTThgrpYSx7yY7gkR7sx_xL8DcQcDiCla_DtoJrhG-_uJFn9pmdwm78-0UcHIwJz1oplOb7n-P2n3FZY2vh1d1YP_Nirtt7NLVbQgDObQyLNwLQ0fr1JBEA6")
                .setTopic(topic)
                .build();

        // Send a message to the device corresponding to the provided
        // registration token.
        String response = FirebaseMessaging.getInstance().send(message);
        // Response is a message ID string.
        System.out.println("Successfully sent message: " + response);

    }catch (FirebaseMessagingException e) {
        System.out.println(e.getMessage());
    }

`

Excepiton:

java.io.IOException: Error getting access token for service account:
Error while calling FCM backend service

can you help me?

@kswillian
Copy link

I've already checked the credentials and firewall issue

@codyoss
Copy link
Member

codyoss commented Apr 2, 2020

Please open a new issue as this is a different exception.

clundin25 pushed a commit to clundin25/google-http-java-client that referenced this issue Aug 11, 2022
* feat: Adds Pluggable Auth support to ADC  (googleapis#895)

* chore(deps): update dependency com.google.http-client:google-http-client-bom to v1.41.5 (googleapis#896)

[![WhiteSource Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| [com.google.http-client:google-http-client-bom](https://togithub.com/googleapis/google-http-java-client) | `1.41.4` -> `1.41.5` | [![age](https://badges.renovateapi.com/packages/maven/com.google.http-client:google-http-client-bom/1.41.5/age-slim)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://badges.renovateapi.com/packages/maven/com.google.http-client:google-http-client-bom/1.41.5/adoption-slim)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://badges.renovateapi.com/packages/maven/com.google.http-client:google-http-client-bom/1.41.5/compatibility-slim/1.41.4)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://badges.renovateapi.com/packages/maven/com.google.http-client:google-http-client-bom/1.41.5/confidence-slim/1.41.4)](https://docs.renovatebot.com/merge-confidence/) |

---

### Release Notes

<details>
<summary>googleapis/google-http-java-client</summary>

### [`v1.41.5`](https://togithub.com/googleapis/google-http-java-client/blob/HEAD/CHANGELOG.md#&#8203;1415-httpsgithubcomgoogleapisgoogle-http-java-clientcomparev1414v1415-2022-03-21)

[Compare Source](https://togithub.com/googleapis/google-http-java-client/compare/v1.41.4...v1.41.5)

</details>

---

### Configuration

📅 **Schedule**: At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, click this checkbox.

---

This PR has been generated by [WhiteSource Renovate](https://renovate.whitesourcesoftware.com). View repository job log [here](https://app.renovatebot.com/dashboard#github/googleapis/google-auth-library-java).

* feat: Add ability to provide PrivateKey as Pkcs8 encoded string googleapis#883 (googleapis#889)

* feat: Add ability to provide PrivateKey as Pkcs8 encoded string googleapis#883

This change adds a new method `setPrivateKeyString` in `ServiceAccountCredentials.Builder` to accept Pkcs8 encoded string representation of private keys.

Co-authored-by: Timur Sadykov <stim@google.com>

* chore: fix downstream check (googleapis#898)

* fix: update branding in ExternalAccountCredentials (googleapis#893)

These changes align the Javadoc comments with the branding that Google uses externally:

+ STS -> Security Token Service
+ GCP -> Google Cloud
+ Remove references to a Google-internal token type

Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly:
- [ ] Make sure to open an issue as a [bug/issue](https://github.com/googleapis/google-auth-library-java/issues/new/choose) before writing your code!  That way we can discuss the change, evaluate designs, and agree on the general idea
- [ ] Ensure the tests and linter pass: Tests are failing, but I don't think that was caused by the changes in this PR
- [ ] Code coverage does not decrease (if any source code was changed): n/a
- [ ] Appropriate docs were updated (if necessary): n/a

* feat: Adds the ExecutableHandler interface for Pluggable Auth

* feat: Adds a Pluggable Auth specific exception

* feat: Adds new PluggableAuthCredentials class that plug into ADC

* feat: Adds unit tests for PluggableAuthCredentials and ExternalAccountCredentials

* Add units tests for GoogleCredentials

* fix: update javadoc/comments

* fix: A concrete ExecutableOptions implementation is not needed

* review: javadoc changes + constants

Co-authored-by: WhiteSource Renovate <bot@renovateapp.com>
Co-authored-by: Navina Ramesh <navi.trinity@gmail.com>
Co-authored-by: Timur Sadykov <stim@google.com>
Co-authored-by: Neenu Shaji <Neenu1995@users.noreply.github.com>
Co-authored-by: Jeff Williams <jeffrey.l.williams@gmail.com>

* feat: finalizes PluggableAuth implementation (googleapis#906)

* Adds ExecutableResponse class

* Adds unit tests for ExecutableResponse

* Adds 3rd party executable handler

* Adds unit tests for PluggableAuthHandler

* Fix build issues

* don't fail on javadoc errors

* feat: Improve Pluggable Auth error handling (googleapis#912)

* feat: improves pluggable auth error handling

* cleanup

* fix: consume input stream immediately for Pluggable Auth (googleapis#915)

* feat: improves pluggable auth error handling

* cleanup

* fix: consume input stream immediately so that the spawned process will not hang if the STDOUT buffer is filled.

* fix: fix merge

* fix: review comments

* fix: refactor to keep ImpersonatedCredentials final (googleapis#917)

* fix: adds more documentation for InternalProcessBuilder and moves it to the bottom of the file

* fix: keep ImpersonatedCredentials final

* fix: make sure executor is shutdown

Co-authored-by: WhiteSource Renovate <bot@renovateapp.com>
Co-authored-by: Navina Ramesh <navi.trinity@gmail.com>
Co-authored-by: Timur Sadykov <stim@google.com>
Co-authored-by: Neenu Shaji <Neenu1995@users.noreply.github.com>
Co-authored-by: Jeff Williams <jeffrey.l.williams@gmail.com>
Co-authored-by: Emily Ball <emilyball@google.com>
clundin25 pushed a commit to clundin25/google-http-java-client that referenced this issue Aug 11, 2022
* feat: Adds Pluggable Auth support to ADC  (googleapis#895)

* chore(deps): update dependency com.google.http-client:google-http-client-bom to v1.41.5 (googleapis#896)

[![WhiteSource Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| [com.google.http-client:google-http-client-bom](https://togithub.com/googleapis/google-http-java-client) | `1.41.4` -> `1.41.5` | [![age](https://badges.renovateapi.com/packages/maven/com.google.http-client:google-http-client-bom/1.41.5/age-slim)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://badges.renovateapi.com/packages/maven/com.google.http-client:google-http-client-bom/1.41.5/adoption-slim)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://badges.renovateapi.com/packages/maven/com.google.http-client:google-http-client-bom/1.41.5/compatibility-slim/1.41.4)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://badges.renovateapi.com/packages/maven/com.google.http-client:google-http-client-bom/1.41.5/confidence-slim/1.41.4)](https://docs.renovatebot.com/merge-confidence/) |

---

### Release Notes

<details>
<summary>googleapis/google-http-java-client</summary>

### [`v1.41.5`](https://togithub.com/googleapis/google-http-java-client/blob/HEAD/CHANGELOG.md#&#8203;1415-httpsgithubcomgoogleapisgoogle-http-java-clientcomparev1414v1415-2022-03-21)

[Compare Source](https://togithub.com/googleapis/google-http-java-client/compare/v1.41.4...v1.41.5)

</details>

---

### Configuration

📅 **Schedule**: At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, click this checkbox.

---

This PR has been generated by [WhiteSource Renovate](https://renovate.whitesourcesoftware.com). View repository job log [here](https://app.renovatebot.com/dashboard#github/googleapis/google-auth-library-java).

* feat: Add ability to provide PrivateKey as Pkcs8 encoded string googleapis#883 (googleapis#889)

* feat: Add ability to provide PrivateKey as Pkcs8 encoded string googleapis#883

This change adds a new method `setPrivateKeyString` in `ServiceAccountCredentials.Builder` to accept Pkcs8 encoded string representation of private keys.

Co-authored-by: Timur Sadykov <stim@google.com>

* chore: fix downstream check (googleapis#898)

* fix: update branding in ExternalAccountCredentials (googleapis#893)

These changes align the Javadoc comments with the branding that Google uses externally:

+ STS -> Security Token Service
+ GCP -> Google Cloud
+ Remove references to a Google-internal token type

Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly:
- [ ] Make sure to open an issue as a [bug/issue](https://github.com/googleapis/google-auth-library-java/issues/new/choose) before writing your code!  That way we can discuss the change, evaluate designs, and agree on the general idea
- [ ] Ensure the tests and linter pass: Tests are failing, but I don't think that was caused by the changes in this PR
- [ ] Code coverage does not decrease (if any source code was changed): n/a
- [ ] Appropriate docs were updated (if necessary): n/a

* feat: Adds the ExecutableHandler interface for Pluggable Auth

* feat: Adds a Pluggable Auth specific exception

* feat: Adds new PluggableAuthCredentials class that plug into ADC

* feat: Adds unit tests for PluggableAuthCredentials and ExternalAccountCredentials

* Add units tests for GoogleCredentials

* fix: update javadoc/comments

* fix: A concrete ExecutableOptions implementation is not needed

* review: javadoc changes + constants

Co-authored-by: WhiteSource Renovate <bot@renovateapp.com>
Co-authored-by: Navina Ramesh <navi.trinity@gmail.com>
Co-authored-by: Timur Sadykov <stim@google.com>
Co-authored-by: Neenu Shaji <Neenu1995@users.noreply.github.com>
Co-authored-by: Jeff Williams <jeffrey.l.williams@gmail.com>

* feat: finalizes PluggableAuth implementation (googleapis#906)

* Adds ExecutableResponse class

* Adds unit tests for ExecutableResponse

* Adds 3rd party executable handler

* Adds unit tests for PluggableAuthHandler

* Fix build issues

* don't fail on javadoc errors

* feat: Improve Pluggable Auth error handling (googleapis#912)

* feat: improves pluggable auth error handling

* cleanup

* fix: consume input stream immediately for Pluggable Auth (googleapis#915)

* feat: improves pluggable auth error handling

* cleanup

* fix: consume input stream immediately so that the spawned process will not hang if the STDOUT buffer is filled.

* fix: fix merge

* fix: review comments

* fix: refactor to keep ImpersonatedCredentials final (googleapis#917)

* fix: adds more documentation for InternalProcessBuilder and moves it to the bottom of the file

* fix: keep ImpersonatedCredentials final

* feat: documents pluggable auth in README

* fix: provider

* fix: update table of contents

* fix: update

Co-authored-by: WhiteSource Renovate <bot@renovateapp.com>
Co-authored-by: Navina Ramesh <navi.trinity@gmail.com>
Co-authored-by: Timur Sadykov <stim@google.com>
Co-authored-by: Neenu Shaji <Neenu1995@users.noreply.github.com>
Co-authored-by: Jeff Williams <jeffrey.l.williams@gmail.com>
Co-authored-by: Emily Ball <emilyball@google.com>
@SanketNikam18062000
Copy link

I've already checked the credentials and firewall issue

hy guys!

I'm trying to notify my app using the FCM but when i send the request i'm surprised by an exception.

My send code:

` try{

        Message message = Message.builder()
                .putData("test", "test")
                .putData("test", "test")
                //.setToken("dla3GnhWQjc:APA91bH3dE2St0dLPMmhhTThgrpYSx7yY7gkR7sx_xL8DcQcDiCla_DtoJrhG-_uJFn9pmdwm78-0UcHIwJz1oplOb7n-P2n3FZY2vh1d1YP_Nirtt7NLVbQgDObQyLNwLQ0fr1JBEA6")
                .setTopic(topic)
                .build();

        // Send a message to the device corresponding to the provided
        // registration token.
        String response = FirebaseMessaging.getInstance().send(message);
        // Response is a message ID string.
        System.out.println("Successfully sent message: " + response);

    }catch (FirebaseMessagingException e) {
        System.out.println(e.getMessage());
    }

`

Excepiton:

java.io.IOException: Error getting access token for service account: Error while calling FCM backend service

can you help me?

have you got solution?
bz I am getting also same error.

@neewaz
Copy link

neewaz commented Nov 30, 2023

it was firewall issue , thanks alot

On Fri, Jan 3, 2020 at 1:38 AM Cody Oss @.***> wrote: Yes that is correct, although Firebase does have its own auth as well: https://firebase.google.com/docs/auth Are you still having issues? — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub <#917?email_source=notifications&email_token=AD5HJ57TG5ZO64XTSK67E7TQ3ZUFHA5CNFSM4J3GZ27KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEH7VKDA#issuecomment-570381580>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AD5HJ57YDLTJRHO5DYVOV3TQ3ZUFHANCNFSM4J3GZ27A .

Hi, I am having the similar issue. What did you change in the firewall to make it work? Is there any list of IP-Addresses to be whitelisted?

@dineshsraman
Copy link

Is there any list of IP-Addresses to

Was this sorted? We too have a some issue in Firebase Messaging. Error seems to be different, but we are stuck in getting the access token and network team is analyzing the issue.

Error : Error obtaining access token: Error getting access token for service account: Remote host terminated the handshake,iss.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs more info This issue needs more information from the customer to proceed. type: question Request for information or clarification. Not an issue.
Projects
None yet
Development

No branches or pull requests

7 participants