Created
June 7, 2012 16:38
-
-
Save sealskej/2889927 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@SuppressWarnings("serial") | |
public static final Map<String, String> identifiers = new HashMap<String, String>() { | |
{ | |
put("google", "https://www.google.com/accounts/o8/id"); | |
} | |
}; | |
public static Result auth() { | |
Logger.debug("authenticate"); | |
String providerId = "google"; | |
String providerUrl = identifiers.get(providerId); | |
String returnToUrl = "http://localhost:9000/login/verify"; | |
if (providerUrl == null) { | |
return badRequest("Could not find provider " + providerId); | |
} | |
Map<String, String> attributes = new HashMap<String, String>(); | |
attributes.put("Email", "http://schema.openid.net/contact/email"); | |
attributes.put("FirstName", "http://schema.openid.net/namePerson/first"); | |
attributes.put("LastName", "http://schema.openid.net/namePerson/last"); | |
Promise<String> redirectUrl = OpenID.redirectURL(providerUrl, returnToUrl, attributes); | |
return redirect(redirectUrl.get()); | |
} | |
public static Result verify() { | |
Logger.debug("verifyLogin"); | |
Promise<UserInfo> userInfoPromise = OpenID.verifiedId(); | |
UserInfo userInfo = userInfoPromise.get(); | |
JsonNode json = Json.toJson(userInfo); | |
return ok(json); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
GET /login/auth controllers.Application.auth() | |
GET /login/verify controllers.Application.verify() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi I tried the same example but getting below error. can you please help me in resolving this;
[debug] application - authenticate
[error] play - Cannot invoke the action, eventually got an error: java.net.ConnectException: https://www.google.com/accounts/o8/id
[error] application -
! @6md8071nd - Internal server error, for (GET) [/login/auth] ->
play.api.Application$$anon$1: Execution exception[[ConnectException: https://www.google.com/accounts/o8/id]]
at play.api.Application$class.handleError(Application.scala:293) ~[play_2.10.jar:2.2.3]
at play.api.DefaultApplication.handleError(Application.scala:399) [play_2.10.jar:2.2.3]
at play.core.server.netty.PlayDefaultUpstreamHandler$$anonfun$3$$anonfun$applyOrElse$3.apply(PlayDefaultUpstreamHandler.scala:264) [play_2.10.jar:2.2.3]
at play.core.server.netty.PlayDefaultUpstreamHandler$$anonfun$3$$anonfun$applyOrElse$3.apply(PlayDefaultUpstreamHandler.scala:264) [play_2.10.jar:2.2.3]
at scala.Option.map(Option.scala:145) [scala-library.jar:na]
at play.core.server.netty.PlayDefaultUpstreamHandler$$anonfun$3.applyOrElse(PlayDefaultUpstreamHandler.scala:264) [play_2.10.jar:2.2.3]
Caused by: java.net.ConnectException: https://www.google.com/accounts/o8/id
at com.ning.http.client.providers.netty.NettyConnectListener.operationComplete(NettyConnectListener.java:103) ~[async-http-client.jar:na]
at org.jboss.netty.channel.DefaultChannelFuture.notifyListener(DefaultChannelFuture.java:427) ~[netty.jar:na]
at org.jboss.netty.channel.DefaultChannelFuture.addListener(DefaultChannelFuture.java:145) ~[netty.jar:na]
at com.ning.http.client.providers.netty.NettyAsyncHttpProvider.doConnect(NettyAsyncHttpProvider.java:1068) ~[async-http-client.jar:na]
at com.ning.http.client.providers.netty.NettyAsyncHttpProvider.execute(NettyAsyncHttpProvider.java:890) ~[async-http-client.jar:na]
at com.ning.http.client.AsyncHttpClient.executeRequest(AsyncHttpClient.java:520) ~[async-http-client.jar:na]
Caused by: java.nio.channels.UnresolvedAddressException: null
at sun.nio.ch.Net.checkAddress(Unknown Source) ~[na:1.8.0_31]
at sun.nio.ch.SocketChannelImpl.connect(Unknown Source) ~[na:1.8.0_31]
at org.jboss.netty.channel.socket.nio.NioClientSocketPipelineSink.connect(NioClientSocketPipelineSink.java:108) ~[netty.jar:na]
at org.jboss.netty.channel.socket.nio.NioClientSocketPipelineSink.eventSunk(NioClientSocketPipelineSink.java:70) ~[netty.jar:na]
at org.jboss.netty.handler.ssl.SslHandler.handleDownstream(SslHandler.java:596) ~[netty.jar:na]
at org.jboss.netty.handler.codec.oneone.OneToOneEncoder.handleDownstream(OneToOneEncoder.java:54) ~[netty.jar:na]
Thanks in Advance.