Interface play.api.Plugin is not assignable from class services.InMemoryUserService

173 Views Asked by At

I am trying to implement OAUTH2 authentication with play 2.4.4 (same with 2.4.2) and SecureSocial, my Scala version is 2.11.7

I am following the tutorial at SecureSocial with the Githhub example at SecureSocial demo

I begin with not having anything in file play.plugins and i try to login with one of the following

http://localhost:9000/api/custom/login

I end up with the following error:

[RuntimeException: [securesocial] Missing properties for provider 'facebook'. Verify your configuration file is properly set.]

OK, 2 problems, 1 no login, 2 even if there was a login i am not interested in facebook, only google.

Following the configuration on SecureSocial website there is a file play.plugin where you need to address the providers you want and the user service to handle authentication (the user service can be found in the github example)

my play.plugins looks like this:

9998:services.InMemoryUserService
10002:securesocial.core.providers.GoogleProvider

Now when i try the same URL again i get the following error:

java.lang.ClassCastException: interface play.api.Plugin is not assignable from class services.InMemoryUserService
 play.utils.Reflect$.getClass(Reflect.scala:145)
 play.api.Plugins$$anonfun$loadPlugins$1.apply(Plugins.scala:88)
 play.api.Plugins$$anonfun$loadPlugins$1.apply(Plugins.scala:87)
 scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:245)
 scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:245)
 scala.collection.immutable.List.foreach(List.scala:381)
 scala.collection.TraversableLike$class.map(TraversableLike.scala:245)
 scala.collection.immutable.List.map(List.scala:285)
 play.api.Plugins$.loadPlugins(Plugins.scala:87)
 play.api.Plugins$$anonfun$apply$4.apply(Plugins.scala:100)
 ...

WHAT!?

Ok, now i try with the other authentication url:

http://localhost:9000/auth/authenticate/google

I get the same error, and if i remote the play.plugins i get a Guice exception which i have no idea how to fix.

Thanks

1

There are 1 best solutions below

0
Jorge On

The online docs are for an older version (they have not been updated yet).

Plugins are not used anymore in the module. What you have now is a RuntimeEnvironment class that you use to configure the services you want to use. There's a RuntimeEnvironment.Default class that you can use as a base as well and it's what the demo is using here: https://github.com/jaliss/securesocial/blob/3.0-M4/samples/scala/demo/app/Global.scala#L27.

In your case, you'll only include the Google provider, so basically override providers as:

override lazy val providers = ListMap(
     include(
        new GoogleProvider(routes,cacheService,oauth2ClientFor(GoogleProvider.Google)))
     )

You'll need to create your app in the Google console to get your oauth keys. You need to set those keys in securesocial.conf (look for the google section). It's important that you make sure to enable the Google+ API for your app in the Google console or the login won't work due to lack of permissions.

Once you have your environment defined you need to create a module to bind it. The sample is doing that here: https://github.com/jaliss/securesocial/blob/3.0-M4/samples/scala/demo/app/DemoModule.scala#L6.

Finally you tell Play to use your module in application.conf: https://github.com/jaliss/securesocial/blob/3.0-M4/samples/scala/demo/conf/application.conf#L13.