2009-02-19

How to use OpenID to sign on with Google account

Recently Google announced its support for OpenID, called "Federated Login", to let any site enable their users to sign on by their Google accounts, without registrations.

This is really a good news, and for Java developers they can write some code to make the 3rd-part site to connect to Google. There are already lots of libaries that can be used in J2EE. However, after I do some evaluation of these libaries, I do not find a suitable libary. The well-known "OpenID4Java", is too large (46MB!), with dependencies on many other libaries. So I decided to write a small, but very lightweight libary to support OpenID 2.0 spec, called "JOpenID".

It is very small, with only 48KB including both source & binary. You can download from http://code.google.com/p/jopenid/downloads/list.


It has been fully tested based on Google accounts. However, I think it also can support Yahoo! OpenID, but with little information provided by Yahoo! I do not test yet.

5 条评论:

Karl in USA 说...

Thanks Michael. I am very interested in using your JOpenID package.

I have the following questions:

How can I test it in a local Tomcat servlet development environment where my url is http://localhost:8080?

Is it possible for me to have user enter their email and then send the authentication request?

Thanks.

Karl in USA 说...

Hi Michael - it's me again.

I answered for myself the two questions I asked before (1 - no and 2 - maybe if you code your own).

Now I want to make sure I understand the comments in your main() example code:

// Copy the authentication URL in browser, // And after successfully sign on in browser, // enter the URL from address bar of browser:

Do you mean the web app end user has to manually cut and paste urls out of and back in to their browser address bar?

Xuefeng 说...

Hi Karl
you can edit your hosts file to add:
www.example.com 127.0.0.1

then you can use http://www.example.com to access local tomcat server.

in web app, there is a redirect action for user, there is only 1 click for user in the whole sign on process if he/she remember his/her google account.

Dimas 说...

Hi Michael,

I've downloaded and i've tested the example code avaliable on: http://code.google.com/p/jopenid/source/browse/trunk/JOpenId/src/com/javaeedev/openid/Main.java

It worked well. But i'm wondering one thing: As i saw on a screencast video about openId, it's possible to get another informations about the user besides its e-mail (like name and country).
Does jopenid support it?

If so, could u explain me how do i do it?

Xuefeng 说...

hi Dimas
yes you can get other info. See
http://code.google.com/p/jopenid/source/browse/trunk/JOpenId/src/com/javaeedev/openid/OpenIdManager.java

line 229:
list.add("openid.ext1.type.email=http://schema.openid.net/contact/email");
list.add("openid.ext1.required=email");

other ext can be found in http://www.axschema.org/types/

but most openid providers may not provides all of these fields.