Adding OAuth to JOpenId

32 views
Skip to first unread message

dewphy

unread,
Oct 24, 2010, 1:28:33 PM10/24/10
to JOpenID Discussion Group
Hello,

I am struggling in extending the JOpenId library to handle the hybrid
protocol (OpenID+OAuth)

I manage to get an authorized token back after adding the OAuth
parameters to the getAuthenticationUrl() method (obviously, this works
for only for Google so far):

.append("openid.ns.ext2=http://specs.openid.net/extensions/
oauth/1.0");
.append("openid.ext2.consumer=contactninja.dyndns.org");
.append("openid.ext2.scope=https://www.google.com/m8/feeds/");

Now, to get the access token I created a OAuthGetAccessToken
connexion:

int millis = (int) System.currentTimeMillis() * -1;
int time = (int) millis / 1000;
URLConnection connection
= new URL("https://www.google.com/accounts/
OAuthGetAccessToken?"
+ "oauth_consumer_key=contactninja.dyndns.org"
+ "&oauth_nonce=" +String.valueOf(millis)
+ "&oauth_timestamp=" + String.valueOf(time)
+ "&oauth_signature_method=HMAC-SHA1"
+ "&oauth_signature=???"
+ "&oauth_token=" + THE_AUTHORIZED_TOKEN_I_RECEIVED
+ "&oauth_version=1.0").openConnection();

BUT, I cannot figure out how to construct "&oauth_signature=???". The
description is here: http://code.google.com/apis/accounts/docs/OAuth_ref.html#SigningOAuth

Any idea, subjection ? It would be very appreciated!
Thank you!

Philippe

Erwin Quinto

unread,
Oct 30, 2010, 1:38:10 AM10/30/10
to jopenid-disc...@googlegroups.com
Hi Philippe,

You basically need an Oauth HMAC-SHA1 Signer. Take a look at a sample implementation here:
http://code.google.com/p/google-api-java-client/source/browse/google-api-client/src/com/google/api/client/auth/oauth/OAuthHmacSigner.java

--Erwin

Philippe DE WAGTER

unread,
Oct 30, 2010, 2:19:38 AM10/30/10
to jopenid-disc...@googlegroups.com
Thank you Erwin for the link, and also for the great JOpenId library.

I finally manage to get the hybrid OpenId+OAuth working, but I am still a bit confused about what byte[] key to use in the getHmacSha1() function. During the verification of the signature, the association.getRawMac() is used (and behind the scene the method Base64.decode(mac_key) is called), while during the additional step I wrote to get the access token, I need to use "$MY_CONSUMER_SECRET&".getBytes("UTF-8")

How come that to get the byte[] for the key, in the first case I Base64.decode(key), while in the second case I need key.getBytes("UTF-8") ?

If you have some clue for that, I would appreciate,
Thank you!

Philippe
Reply all
Reply to author
Forward
0 new messages