joscha / play-authenticate

An authentication plugin for Play Framework 2.x (Java)
http://joscha.github.com/play-authenticate/
Other
807 stars 367 forks source link

How to use this library in an existing Play? #331

Closed 030 closed 7 years ago

030 commented 7 years ago

I have added the following to the build.sbt

"com.feth" %% "play-authenticate" % "0.8.1"

added <a href="@com.feth.play.module.pa.controllers.routes.Authenticate.logout">Logout</a> to my app/views/index.scala.html

when the app is run it results in:

[error] /path/to/play/app/views/index.scala.html:9: object routes is not a member of package com.feth.play.module.pa.controllers
[error]         <a href="@com.feth.play.module.pa.controllers.routes.Authenticate.logout">Logout</a>
[error]

How to add the library so that I do not have to copy all the code?

I have checked https://github.com/joscha/play-authenticate/tree/master/samples/java/play-authenticate-simple-oauth

My question is whether I should copy all the java code that resides in the app dir or could this be included using the build.sbt?

ghost commented 7 years ago

No, you don't need to copy all of the code in the app directory. But, adding the dependency only gets you so far.

At minimum, you will need your own AbstractUserService implementation and a Resolver implementation. You will also need to bind them in your default module (if you have one), or create a new one.

Check out the other example if you want more than just OAuth.

030 commented 7 years ago

I do not have to copy the Application.java for example? If I do not do that then the PlayAuthenticate does not seem to be called from the index.scala.html. I have not copied the simple example from this repo, the authentication works. Is this the way to go? I am looking for a kick start: How to use this in a App, e.g. add this to sbt and then to this do that, but now I copied all the code.