[OAUTH-WG] Oauth signature problem
Sunil Pal <sunilpal73@gmail.com> Thu, 12 September 2013 07:05 UTC
Return-Path: <sunilpal73@gmail.com>
X-Original-To: oauth@ietfa.amsl.com
Delivered-To: oauth@ietfa.amsl.com
Received: from localhost (localhost [127.0.0.1]) by ietfa.amsl.com (Postfix) with ESMTP id D9EDC11E824C for <oauth@ietfa.amsl.com>; Thu, 12 Sep 2013 00:05:40 -0700 (PDT)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: 0.767
X-Spam-Level:
X-Spam-Status: No, score=0.767 tagged_above=-999 required=5 tests=[BAYES_00=-2.599, HTML_MESSAGE=0.001, J_CHICKENPOX_36=0.6, J_CHICKENPOX_37=0.6, NO_RELAYS=-0.001, SARE_URI_CONS9=1.666, URI_NOVOWEL=0.5]
Received: from mail.ietf.org ([12.22.58.30]) by localhost (ietfa.amsl.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id VcuCFPhaGdKa for <oauth@ietfa.amsl.com>; Thu, 12 Sep 2013 00:05:39 -0700 (PDT)
Received: from mail-bk0-x234.google.com (mail-bk0-x234.google.com [IPv6:2a00:1450:4008:c01::234]) by ietfa.amsl.com (Postfix) with ESMTP id 9C85A11E8175 for <oauth@ietf.org>; Thu, 12 Sep 2013 00:05:38 -0700 (PDT)
Received: by mail-bk0-f52.google.com with SMTP id e11so3911652bkh.39 for <oauth@ietf.org>; Thu, 12 Sep 2013 00:05:37 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=O/FuLsr6rYT6rQk7lb7Axb9g4FdeDfEXsLjMm41i9GY=; b=sjUS/Qeey1MdSRuwqQ02vEwjwKnPgN1CXY0aYBzxStMrsyfr++CPzaqV+WTORNmAnZ 51kmGF8yjcNUMog+17u8l5VsIzAOOdSXDPS4cmBxAaI5KJR1mb6R9wh2KksLDK1kpSGb CzDdCLml6rrZ//OIJVbHmyV6Sw+j13XuNYJn6dXgKpExSlAgCCQukkghlKFJBOUAURqB uvzF5Va1d5RCFxTH5A8Exjm4zF74xOfLlMq4Zu5Soaa/tnsr05nL6qYMFzGcDC88kMxa Q8beqoDtNIVyfzuDdb7UVV40L6elIO5q5ROdm7CU2P+i/GUW6ZVcZxliGc+ZML92lwS0 DO6A==
MIME-Version: 1.0
X-Received: by 10.204.71.133 with SMTP id h5mr5179905bkj.0.1378969537392; Thu, 12 Sep 2013 00:05:37 -0700 (PDT)
Received: by 10.204.103.3 with HTTP; Thu, 12 Sep 2013 00:05:37 -0700 (PDT)
Date: Thu, 12 Sep 2013 12:35:37 +0530
Message-ID: <CAAU+EYCnSXMMuvKgL7bKCkEk8e9BtqCwKDhn962C0seKwtLRhg@mail.gmail.com>
From: Sunil Pal <sunilpal73@gmail.com>
To: oauth@ietf.org
Content-Type: multipart/alternative; boundary="047d7b8747ca6ee1e704e62a5d73"
Subject: [OAUTH-WG] Oauth signature problem
X-BeenThere: oauth@ietf.org
X-Mailman-Version: 2.1.12
Precedence: list
List-Id: OAUTH WG <oauth.ietf.org>
List-Unsubscribe: <https://www.ietf.org/mailman/options/oauth>, <mailto:oauth-request@ietf.org?subject=unsubscribe>
List-Archive: <http://www.ietf.org/mail-archive/web/oauth>
List-Post: <mailto:oauth@ietf.org>
List-Help: <mailto:oauth-request@ietf.org?subject=help>
List-Subscribe: <https://www.ietf.org/mailman/listinfo/oauth>, <mailto:oauth-request@ietf.org?subject=subscribe>
X-List-Received-Date: Thu, 12 Sep 2013 07:05:41 -0000
How to generate the correct oauth_signature in apex.Here is the code for generating oauth_nonce, oauth_timestamp and oauth_signature. But not getting the correct oauth_signature // Generate a unique combination of numbers and alphabets for oauth-nonce String nonce = String.valueOf(Crypto.getRandomLong()); Blob key = Blob.valueOf(nonce); String Keyy = 'XXXXXXXXXXXXXXXX'; Long timee=DateTime.now().getTime(); Integer random = Crypto.getRandomInteger(); Integer time2 = integer.valueOf(timee) +random; String str2= string.valueOf(time2); Blob key2= Blob.valueOf(str2); Blob keyHash = Crypto.generateDigest('MD5',key2); String hexDigest = EncodingUtil.convertToHex(keyHash); // Generate timestamp for current time String timestamp = String.valueOf(DateTime.now().getTime()/1000); // Create map for maintaining the parameters used to create signature map<String, String> parameters = new Map<String, String>(); parameters.put('oauth_consumer_key','ZZZZZZZZZZZZ'); parameters.put('oauth_signature_method','HMAC-SHA1'); parameters.put('oauth_timestamp',timestamp); parameters.put('oauth_nonce',hexDigest); parameters.put('oauth_version','1.0'); // Form the gneral HttpRequest Http h = new Http(); HttpRequest req = new HttpRequest(); req.setMethod('GET'); req.setEndpoint('https://YYYYYYYYYYY.com/people/1234567/identity'); String host = req.getEndpoint(); Integer n = host.indexOf('?'); List<String> keys = new List<String>(); keys.addAll(parameters.keySet()); keys.sort(); String str = keys.get(0)+'='+parameters.get(keys.get(0)); for(Integer i=1;i<keys.size();i++) { str = str +'&'+keys.get(i)+'='+parameters.get(keys.get(i)); } String s = req.getMethod().toUpperCase()+ '&' + EncodingUtil.urlEncode(host, 'UTF-8') +'&'+ EncodingUtil.urlEncode(str, 'UTF-8'); Blob sig = Crypto.generateMac('Hmac-SHA1', Blob.valueOf(s), Blob.valueOf(Keyy)); Blob signature1 = Blob.valueOf(EncodingUtil.convertToHex(sig)); String signature = EncodingUtil.base64encode(signature1); req.setEndpoint('https://XXXXXXXXX.com/people/1234567/identity?oauth_version=1.0&oauth_nonce='+hexDigest+'&oauth_timestamp='+timestamp+'&oauth_consumer_key=ZZZZZZZZZZZZZ&oauth_signature_method=HMAC-SHA1&oauth_signature='+signature+''); HttpResponse res = h.send(req); System.debug('Response from request token request: ('+res.getStatusCode()+')'+res.getBody()); --- Thanks And Warm Regards Sunil Kumar Pal
- [OAUTH-WG] Oauth signature problem Sunil Pal