0

So, I have an Android app which means I'm not using a browser (I'll explain why this is important in few lines) and I wish to use Security.Authenticator with Play! 2.3.8

Basically, Play uses the current session (which is directly related to the browser), check what's in there by using String getUserame(Context ctx) and send back the username if this one exist. If not, then it returns a HTTP redirect using Result onUnauthorized(Context ctx)

Here is my problem: I use Play as a server for remote apps. How can I use Play's authentication provided methods with my app? It's tricky because of course, I can't store something in session due to the fact I'm not using any browser.

Do you guys have some workaround or solutions for this?

sebster
  • 1,322
  • 2
  • 18
  • 29
Mornor
  • 3,471
  • 8
  • 31
  • 69
  • That's the default behavior of `Authenticator`. You can easily override the `getUsername` method and detect if your user is authenticated in the headers of the request or somewhere else. – c4k Apr 16 '15 at 16:10

1 Answers1

1

Play uses the current session (which is directly related to the browser)... I can't store something in session due to the fact I'm not using any browser.

The above is false.

You can easily store cookies in the Android's CookieStore so you can safely use Play's session cookie with it.

Relevant SO questions that will help you figure it out how to do this Android side:

Android: How to store cookies?

Storing and restoring cookies in Android (persistent cookie storage)

Community
  • 1
  • 1
sebster
  • 1,322
  • 2
  • 18
  • 29