Play! and OpenID

125 views
Skip to first unread message

Antho

unread,
Nov 24, 2009, 5:37:18 PM11/24/09
to play-framework
Hi !

I've searched a lot of information on OpenID and how Play! uses it but
I still need some help.

I read the OpenID integration on homepage and the Play! API doc but
it's incomplete.

I want to integrate OpenID on my (still under construction) website
but I can't find a way to get any information back from the provider
(Google in my case for the moment).

I tried to print "verifiedUser.extensions.keySet()" and
"verifiedUser.extensions.values()" but all I get is "[]" in both
cases.

What do I need to do to make it work ? Is there a configuration's
problem from my google account or is it something with Play ?

Thank you in advance !

Guillaume Bort

unread,
Nov 24, 2009, 5:50:48 PM11/24/09
to play-fr...@googlegroups.com
Hi,

Here is a sample that should work with google:

public static void authenticate() {
if(OpenID.isAuthenticationResponse()) {
// Retrieve the verified id
UserInfo user = OpenID.getVerifiedID();
if(user == null) {
flash.put("error", "Oops. Authentication has failed");
index();
} else {
session.put("user.id", user.id);
session.put("user.email", user.extensions.get("email"));
index();
}
} else {
// Verify the id
if(!OpenID.id("https://www.google.com/accounts/o8/id").required("email",
"http://axschema.org/contact/email").verify()) {
flash.put("error", "Oops. Cannot contact google");
index();
}
}

Guillaume.
> --
>
> You received this message because you are subscribed to the Google Groups "play-framework" group.
> To post to this group, send email to play-fr...@googlegroups.com.
> To unsubscribe from this group, send email to play-framewor...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/play-framework?hl=en.
>
>
>

Antho

unread,
Nov 24, 2009, 6:28:26 PM11/24/09
to play-framework
Thanks Guillaume. It's working.

But I'd like to understand all the details. It seems you added a
condition with "required("email","http://axschema.org/contact/
email").verify()" to make it work.

Why is that ? Do I need to do it with all providers if I want to have
mandatory fields (such as name and email for instance) or can I do a
generic treatment ?

Guillaume Bort

unread,
Nov 24, 2009, 6:56:17 PM11/24/09
to play-fr...@googlegroups.com
Well, OpenID attributes exchange is a mess.

You will find details about attributes supported by google here:
http://code.google.com/apis/accounts/docs/OpenID.html

But there is 2 different specs defined in OpenID to do the same thing:
Simple Registration (SREG) and Attribute Exchange (AX). And when it
comes to use Attribute Exchange there is no really any Standard schema
(google seems to use http://axschema.org, but it is not the only one).

The only information you are sure to find with all OpenID provider is
the OpenID.getVerifiedID(); It is an URL and not an email.

aleung

unread,
Feb 9, 2010, 11:58:25 AM2/9/10
to play-fr...@googlegroups.com
I integrated OpenID in my application to login by Google account.

if (!OpenID.id(openId).required("email", "http://
axschema.org/contact/email").verify()) { // will redirect the user
String errorMessage = "Oops. Cannot contact OpenID
provider for " + openId;
Logger.error(errorMessage);
flash.put("error", errorMessage);
login();
}

It works fine on my local dev environment. But after I uploaded the
application to GAE, the verify call always return false. My log
prints:
play.Logger error: Oops. Cannot contact OpenID provider for
https://www.google.com/accounts/o8/id

I know AppEngine SDK supports Google account but seems it can't be
used in Play framework?

----------
From: Guillaume Bort <guillaume.b...@gmail.com>
Date: Nov 25 2009, 6:50 am

Guillaume Bort

unread,
Feb 10, 2010, 9:47:55 AM2/10/10
to play-fr...@googlegroups.com
Hum, you don't have to use OpenID to log in using Google Account in
Google App Engine. Just use the provided user service:

GAE.login("Application.index");

Look at the sample application (lists-with-gae).

Reply all
Reply to author
Forward
0 new messages