Created
December 12, 2012 13:28
-
-
Save soulfly/4267716 to your computer and use it in GitHub Desktop.
QuickBlox signature generation example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// make query | |
long timestamp = System.currentTimeMillis()/1000; | |
int nonce = new Random().nextInt(); | |
String signatureParams = String.format("application_id=%s&auth_key=%s&nonce=%s×tamp=%s&user[login]=%s&user[password]=%s", | |
QBQueries.APPLICATION_ID, QBQueries.AUTH_KEY, nonce, timestamp, "test", "test"); | |
String signature = null; | |
try { | |
signature = Signature.calculateHMAC_SHA(signatureParams, QBQueries.AUTH_SECRET); | |
} catch (SignatureException e) { | |
e.printStackTrace(); | |
} | |
// create entity | |
List<NameValuePair> formparams = new ArrayList<NameValuePair>(); | |
formparams.add(new BasicNameValuePair("application_id", QBQueries.APPLICATION_ID)); | |
formparams.add(new BasicNameValuePair("auth_key", QBQueries.AUTH_KEY)); | |
formparams.add(new BasicNameValuePair("nonce", String.valueOf(nonce))); | |
formparams.add(new BasicNameValuePair("timestamp", String.valueOf(timestamp))); | |
formparams.add(new BasicNameValuePair("user[login]", "test")); | |
formparams.add(new BasicNameValuePair("user[password]", "test")); | |
formparams.add(new BasicNameValuePair("signature", signature)); | |
UrlEncodedFormEntity postEntity = null; | |
try { | |
postEntity = new UrlEncodedFormEntity(formparams, "UTF-8"); | |
} catch (UnsupportedEncodingException e1) { | |
e1.printStackTrace(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment