Skip to content

Instantly share code, notes, and snippets.

@soulfly
Created December 12, 2012 13:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save soulfly/4267716 to your computer and use it in GitHub Desktop.
Save soulfly/4267716 to your computer and use it in GitHub Desktop.
QuickBlox signature generation example
// make query
long timestamp = System.currentTimeMillis()/1000;
int nonce = new Random().nextInt();
String signatureParams = String.format("application_id=%s&auth_key=%s&nonce=%s&timestamp=%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