I saw a few questions about this topic, but none answer the part I am stuck on. By the way, based on the issues people are running into, I might suggest giving a default java implementation of the TemplatesPlugin after all.
The problem I have, is that I copied the two needed views from SecureSocial to my views folder, and changed the RequestHeader as others have noted to: play.api.mvc.RequestHeader and now I am getting:
ambiguous implicit values: both method requestHeader in object PlayMagicForJava of type => play.api.mvc.RequestHeader and value request of type play.api.mvc.RequestHeader match expected type play.api.mvc.RequestHeader
Version: Play-2.1.1, Java 7, SecureSocial from Master.
EDIT:
Play Compile:
[error] C:\Java\AwsConsole\app\views\secure\login.scala.html:41: ambiguous impli
cit values:
[error] both method requestHeader in object PlayMagicForJava of type => play.ap
i.mvc.RequestHeader
[error] and value request of type play.api.mvc.RequestHeader
[error] match expected type play.api.mvc.RequestHeader
[error] @provider(p.id)
[error] ^
[error] C:\Java\AwsConsole\app\views\secure\provider.scala.html:20: ambiguous im
plicit values:
[error] both method requestHeader in object PlayMagicForJava of type => play.ap
i.mvc.RequestHeader
[error] and value request of type play.api.mvc.RequestHeader
[error] match expected type play.api.mvc.RequestHeader
[error] <form action = "@securesocial.core.providers.utils.Route
sHelper.authenticateByPost("userpass").absoluteURL(IdentityProvider.sslEnabled)"
[error]
^
[error] two errors found
[error] (compile:compile) Compilation failed
Browsing after Play Run instead:
Internal server error, for (GET) [/] ->
sbt.PlayExceptions$CompilationException: Compilation error[ambiguous implicit va
lues:
both method requestHeader in object PlayMagicForJava of type => play.api.mvc.Re
questHeader
and value request of type play.api.mvc.RequestHeader
match expected type play.api.mvc.RequestHeader]
at sbt.PlayReloader$$anon$2$$anonfun$reload$2$$anonfun$apply$15$$anonfun
$apply$16.apply(PlayReloader.scala:349) ~[na:na]
at sbt.PlayReloader$$anon$2$$anonfun$reload$2$$anonfun$apply$15$$anonfun
$apply$16.apply(PlayReloader.scala:349) ~[na:na]
at scala.Option.map(Option.scala:133) ~[scala-library.jar:na]
at sbt.PlayReloader$$anon$2$$anonfun$reload$2$$anonfun$apply$15.apply(Pl
ayReloader.scala:349) ~[na:na]
at sbt.PlayReloader$$anon$2$$anonfun$reload$2$$anonfun$apply$15.apply(Pl
ayReloader.scala:346) ~[na:na]
at scala.Option.map(Option.scala:133) ~[scala-library.jar:na]
The request must be passed explicitely to the login template, the login template must pass the request explicitely to the provider template and the provider template must specify the request when invoking RoutesHelper.authenticateByPost("userpass").absoluteURL. More detailed:
The java TemplatesPlugin should have this getLoginPage implementation:
@Override
public <A> Html getLoginPage(final play.api.mvc.Request<A> request, final Form<Tuple2<String, String>> form,
final Option<String> msg) {
return views.html.login.render(request, form, msg);
}
The parameters (first line) of login.scala.html
should look like this:
@(request: play.api.mvc.RequestHeader, loginForm: play.api.data.Form[(String,String)], errorMsg: Option[String] = None)
Change calls from login.scala.html
to the provider
template to pass the request explicitely (we'll adjust its parameters in the next step).
login.scala.html
line 41, change
@provider(p.id)
to
@provider(request, p.id)
login.scala.html
line 55, change
@provider("userpass", Some(loginForm))
to
@provider(request, "userpass", Some(loginForm))
The parameters (first line) of provider.scala.html
should take the request as first, explicit parameter:
@(request: play.api.mvc.RequestHeader, providerId: String, loginForm: Option[play.api.data.Form[(String, String)]] = None)
Line 20 of the provider template needs to pass the request (so that the correct method is invoked, otherwise you'll get a RuntimeException: There is no HTTP Context available from here
):
<form action = "@securesocial.core.providers.utils.RoutesHelper.authenticateByPost("userpass").absoluteURL(IdentityProvider.sslEnabled)(request)"
This should be all needed changes, if you're using other templates they would have to be adjusted accordingly.
Just to mentiond it: I had changed our java TemplatesPlugin to a scala version (to have it more straight forward).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With