1
votes

I am new to gcm upstream messaging. I am trying to connect to the cloud connection servers via xmpp (using c# agsxmpp library). However, I am getting a not authorized error message from the server and the connection is closed immediately even though the same project number/api key works for http downstream push notifications. Any help is appreciated.

Here is the code.

        var username = Configuration.PROJECT_NUMBER + "@" + Configuration.GCM_SERVER;
        xmpp = new XmppClientConnection
        {
            UseSSL = true,
            UseStartTLS = false,
            Server = Configuration.GCM_SERVER,
            ConnectServer = Configuration.GCM_SERVER,
            Port = Configuration.GCM_PORT,
            Username = username,
            Password = Configuration.GCM_API_KEY,
            AutoResolveConnectServer = true,
            SocketConnectionType = SocketConnectionType.Direct,
            AutoAgents = false,
            KeepAlive = true,
            AutoRoster = false,
            AutoPresence = false,
            UseCompression = false,
            Show = ShowType.chat
        };

        xmpp.OnReadSocketData += Xmpp_OnReadSocketData;
        xmpp.OnWriteSocketData += Xmpp_OnWriteSocketData;
        xmpp.OnLogin += Xmpp_OnLogin;
        xmpp.OnMessage += Xmpp_OnMessage;
        xmpp.OnError += Xmpp_OnError;
        xmpp.OnClose += Xmpp_OnClose;
        xmpp.OnAuthError += Xmpp_OnAuthError;

        xmpp.Open();

    }

And here is the interaction with the ccs (captured from the OnReadSocketData and OnWriteSocketData events)

To CCS<<11:59:58 834
<stream:stream to='gcm.googleapis.com' xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' version='1.0' xml:lang='en'>

From CSS>> 11:59:59 037
<stream:stream from="gcm.googleapis.com" id="AF8BBDE576QWEFF3543" version="1.0" xmlns:stream="http://etherx.jabber.org/streams" xmlns="jabber:client">                                                                                                                                                                                                                                                                                                                                                                                         


From CSS>> 11:59:59 101
<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>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   


To CCS<<11:59:59 115
<auth xmlns="urn:ietf:params:xml:ns:xmpp-sasl" mechanism="PLAIN">ADIwNjAxOTEwOTA2Mlw0MGjkdf4y67fvbjjdgESnhaa2tFX3hIcm56NXhWZndJclpFUmlMbnBqNVFIdkk=</auth>


From CSS>> 11:59:59 312
<failure xmlns="urn:ietf:params:xml:ns:xmpp-sasl"><not-authorized/></failure>ism>X-OAUTH2</mechanism><mechanism>X-GOOGLE-TOKEN</mechanism><mechanism>PLAIN</mechanism></mechanisms></stream:features> 


From CSS>> 11:59:59 314
</stream:stream>urn:ietf:params:xml:ns:xmpp-sasl"><not-authorized/></failure>ism>X-OAUTH2</mechanism><mechanism>X-GOOGLE-TOKEN</mechanism><mechanism>PLAIN</mechanism></mechanisms></stream:features>                
1
You say your just new with GCM Upstream Messaging, am I correct to assume that what you are implementing with this is all just for trying it out? That you're using the gcm-preprod.googleapis.com:5236 port, stuff like that? Just wanted to verify if Configuration.PROJECT_NUMBER = <your_sender_id>? Cheers.AL.
Found this similar post. Few differences: language for implementation and as per my previous comment, he's using the gcm-preprod.googleapis.com. I went ahead and asked if he was able to find what was causing the error on his end. I don't know if it'd be useful though. Let's see. Cheers!AL.
Thanks for the help, I was using <project number>@<gcmserveraddress> as a username, I changed that to just the username and it is working now.yohannist
Great. :D You should post that as an answer and tag it as correct. So that the community and possible future users can see it. :) Might help someone one day. Cheers! :DAL.
yeah, good point.yohannist

1 Answers

1
votes

I changed the username from <Project_Number>@<GCM_Server_Address> to just <Project_Number> and it is working.