EricH206
EricH206

Reputation: 576

Play framework authentication, like htaccess

I have a Play Framework application and i would like to add the simplest authentication method, like .htaccess. Is there something available for Java/Play Framework?

I searched a lot and i didn't find anything. Looked at the documentation for authentication examples, but everything is too big for my project. That's why i need something simple like a .htaccess file.

Upvotes: 1

Views: 708

Answers (3)

pedrorijo91
pedrorijo91

Reputation: 7845

As others have been saying, using .htaccess is not a very good solution.

Play makes it easy to use basic authentication (username + password) by providing a couple of utility methods to write/read session tokens simply by doing:

requestHeader.session.get("sessionToken")

and

val token = generateSessionToken()

Redirect(routes.MyController.index()).withSession(request.session + ("sessionToken" -> token))

More details: https://pedrorijo.com/blog/scala-play-auth/

Upvotes: 0

biesior
biesior

Reputation: 55798

If your only goal is using some temporary authentication for app which will not use authentication in the production .htaccess (a.k.a basic auth) is acceptable solution.

Otherwise you should build the authentication/authorization into your app's logic as ssbb pointed. (there are some ready to use plugins for Play 2.x)

The easiest way for using .htaccess auth is... using it. As that's Apache's mechanism, just use the Apache as a HTTP frontend server to control the access to your Play app. Of course you can also use any other, lighter HTTP server which delivers basic auth like nginx or lighttpd

Upvotes: 2

ssbb
ssbb

Reputation: 1931

htaccess SHOULD NOT BE USE AS AUTHENTICATION METHOD !!!!!!!

May i suggest you https://www.playframework.com/documentation/2.1.0/JavaGuide4

Upvotes: 3

Related Questions