Unable to Connect my App Server to FCM XMPP Server

2019-08-22 18:46发布

问题:

I am trying to connect to FCM XMPP server using Openssl TLS

I have registered a project and have a Server Key and Sender ID. I follow the notes in https://firebase.google.com/docs/cloud-messaging/auth-server#authorize_an_xmpp_connection

All my codes are in C using openssl.

Following are the communications between my App Server and FCM-XMPP Server App Server to FCM-XMPP:

<stream:stream to='fcm-xmpp.googleapis.com' version='1.0' xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams'>

from FCM-XMPP Server:

<stream:stream from="fcm-xmpp.googleapis.com" id="E1204B9D567A6A8A" version="1.0" xmlns:stream="http://etherx.jabber.org/streams" xmlns="jabber:client">
<stream:features><mechanisms xmlns="urn:ietf:params:xml:ns:xmpp-sasl"><mechanism>X-OAUTH2</mechanism><mechanism>X-GOOGLE-TOKEN</mechanism><mechanism>PLAIN</mechanism></mechanisms></stream:features>

App Server to FCM-XMPP:

<auth mechanism='PLAIN' xmlns='urn:ietf:params:xml:ns:xmpp-sasl'>base 64 encoding of <null>sendID@fcm-xmpp.googleapis.com<null>serverKey</auth>

from FCM-XMPP Server:

<failure xmlns="urn:ietf:params:xml:ns:xmpp-sasl"><not-authorized/></failure>

I have a App Server communicating with GCM-XMPP Server. I am running basically the same code and I get

<success xmlns="urn:ietf:params:xml:ns:xmpp-sasl"/>

回答1:

The app-server to FCN-XMPP should be:

<auth xmlns='urn:ietf:params:xml:ns:xmpp-sasl' mechanism='PLAIN'></auth>

The server will then respond with an empty string. That's your signal to now send the encoded data:

<response xmlns="urn:ietf:params:xml:ns:xmpp-sasl">encodedData</response>

for which the encodedData should be the encoded version of:
\0sendID@fcm-xmpp.googleapis.com\0serverKey

If this is successful you will receive the success-tag.

At least all this is the case on my client which i implemented myself.