OpenID for Play Framework

105 views
Skip to first unread message

KuoYing@Taiwan

unread,
Dec 10, 2010, 12:07:20 PM12/10/10
to play-framework
I using OpenID Lib for Play Framework...but I want to get user email
by google account. But...I fail. It is show "null" in terminal.

public static void openid(String openid) throws MessageException {
if (OpenID.isAuthenticationResponse()) {
UserInfo user = OpenID.getVerifiedID();
if (user == null) {
flash.put("error", "Oops. Authentication has failed");
index();
}
session.put("user.email", user.extensions.get("email"));
session.put("id", user.id);
System.out.println(session.get("user.email"));
index();
} else {
OpenID.id(openid).verify(); // will redirect the user
}

Guillaume Bort

unread,
Dec 10, 2010, 3:04:38 PM12/10/10
to play-fr...@googlegroups.com
You need to ask the email to google during the verify process:

OpenID.id(openid).required("lastname", "http://axschema.org/namePerson/last").
required("firstname",
"http://axschema.org/namePerson/first").
required("email", "http://axschema.org/contact/email").
verify();

Google will ask the user for the permission.

> --
> 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.
>
>

--
Guillaume Bort, http://guillaume.bort.fr

For anything work-related, use g...@zenexity.fr; for everything else,
write guillau...@gmail.com

KuoYing@Taiwan

unread,
Dec 11, 2010, 5:29:10 AM12/11/10
to play-framework
But What method by OpenID or UserInfo ... I could get user Email for
String???
> Guillaume Bort,http://guillaume.bort.fr
>
> For anything work-related, use g...@zenexity.fr; for everything else,
> write guillaume.b...@gmail.com

Nicolas Martignole

unread,
Dec 11, 2010, 5:43:40 AM12/11/10
to play-fr...@googlegroups.com
Hi

Here is what I use on express-board.fr

 public static void authenticateOpenIdGoogle() {
        if (OpenID.isAuthenticationResponse()) {
            OpenID.UserInfo verifiedUser = OpenID.getVerifiedID();
            if (verifiedUser == null) {
                flash.error("Erreur OpenID");
                index();
            }

            String userEmail = verifiedUser.extensions.get("email");
            if (userEmail == null) {

                flash.error("Your email address is required, please authorize our site to access it");
                index();
            }

           // Some code remove



            flash.success("Bienvenue "+userEmail);

            showMyProfile();

        } 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();
            }
        }
    }

Nicolas

2010/12/11 KuoYing@Taiwan <stu93...@gmail.com>

KuoYing@Taiwan

unread,
Dec 11, 2010, 12:51:56 PM12/11/10
to play-framework
Thank you very much!! I try it success!!^_______^(very high)
> 2010/12/11 KuoYing@Taiwan <stu93303...@gmail.com>
> > play-framewor...@googlegroups.com<play-framework%2Bunsubscribe@go oglegroups.com>
> > .
> > > > For more options, visit this group athttp://
> > groups.google.com/group/play-framework?hl=en.
>
> > > --
> > > Guillaume Bort,http://guillaume.bort.fr
>
> > > For anything work-related, use g...@zenexity.fr; for everything else,
> > > write guillaume.b...@gmail.com
>
> > --
> > 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<play-framework%2Bunsubscribe@go oglegroups.com>
> > .

harmanjd

unread,
Dec 12, 2010, 7:42:25 PM12/12/10
to play-framework
Is there documentation on play open id support somewhere on the
website ?
> > For more options, visit this group athttp://groups.google.com/group/play-framework?hl=en.
>
> --
> Guillaume Bort,http://guillaume.bort.fr
>
> For anything work-related, use g...@zenexity.fr; for everything else,
> write guillaume.b...@gmail.com

Guillaume Bort

unread,
Dec 13, 2010, 4:57:21 AM12/13/10
to play-fr...@googlegroups.com
http://www.playframework.org/documentation/1.1/openid

> For more options, visit this group at http://groups.google.com/group/play-framework?hl=en.
>
>

--
Guillaume Bort, http://guillaume.bort.fr

For anything work-related, use g...@zenexity.fr; for everything else,

write guillau...@gmail.com

Reply all
Reply to author
Forward
0 new messages