i trying implement google login webapp using oauth 2.0 login. however, while performing step 4 ie. "exchange code access token , id token", when perform post request access , id token, following exception along below stacktrace.
java.net.unknownhostexception: https://accounts.google.com/o/oauth2/token
at java.net.inet4addressimpl.lookupallhostaddr(native method) @ java.net.inetaddress$1.lookupallhostaddr(inetaddress.java:866) @ java.net.inetaddress.getaddressesfromnameservice(inetaddress.java:1258) @ java.net.inetaddress.getallbyname0(inetaddress.java:1211) @ java.net.inetaddress.getallbyname(inetaddress.java:1127) @ java.net.inetaddress.getallbyname(inetaddress.java:1063) @ org.apache.http.impl.conn.defaultclientconnectionoperator.resolvehostname(defaultclientconnectionoperator.java:242) @ org.apache.http.impl.conn.defaultclientconnectionoperator.openconnection(defaultclientconnectionoperator.java:130) @ org.apache.http.impl.conn.abstractpoolentry.open(abstractpoolentry.java:150) @ org.apache.http.impl.conn.abstractpooledconnadapter.open(abstractpooledconnadapter.java:121) @ org.apache.http.impl.client.defaultrequestdirector.tryconnect(defaultrequestdirector.java:575) @ org.apache.http.impl.client.defaultrequestdirector.execute(defaultrequestdirector.java:425) @ org.apache.http.impl.client.abstracthttpclient.execute(abstracthttpclient.java:820) @ org.apache.http.impl.client.abstracthttpclient.execute(abstracthttpclient.java:776) @ dispatch.classic.blockinghttp$class.dispatch$classic$blockinghttp$$execute(http.scala:45) @ dispatch.classic.blockinghttp$$anonfun$execute$1$$anonfun$apply$3.apply(http.scala:58) @ dispatch.classic.blockinghttp$$anonfun$execute$1$$anonfun$apply$3.apply(http.scala:58) @ scala.option.getorelse(option.scala:120) @ dispatch.classic.blockinghttp$$anonfun$execute$1.apply(http.scala:58) @ dispatch.classic.http.pack(http.scala:25) @ dispatch.classic.blockinghttp$class.execute(http.scala:53) @ dispatch.classic.http.execute(http.scala:21) @ dispatch.classic.httpexecutor$class.x(executor.scala:36) @ dispatch.classic.http.x(http.scala:21) @ dispatch.classic.httpexecutor$class.when(executor.scala:50) @ dispatch.classic.http.when(http.scala:21) @ dispatch.classic.httpexecutor$class.apply(executor.scala:60) @ dispatch.classic.http.apply(http.scala:21)
following details of post request:
import dispatch.classic._ val req = :/("https://accounts.google.com/o/oauth2/token").secure val params = map( "code" -> code, "client_id" -> googleclientid, "client_secret" -> googleclientsecret, "redirect_uri" -> googleauthuri, "grant_type" -> "authorization_code" ) val res = parse(h(req << params as_str))
where,
code auth code returned in pervious request https://accounts.google.com/o/oauth2/auth [step 2 on here ]
googleauthuri "https://localhost/portal/google/login
" have specified in google api developer console.
also using scala , dispatch implement this.
turns out problem how dispatch finds out hostname request url. in case
val req = :/("https://accounts.google.com/o/oauth2/token").secure
dispatch interprets hostname "https://accounts.google.com/o/oauth2/token" not available , hence throws exception. counter need structure req url as,
val req = :/("accounts.google.com"/"o"/"oauth2"/"token").secure
Comments
Post a Comment