Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8444587
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T09:25:51+00:00 2026-06-10T09:25:51+00:00

I have been digging into Play2!Scala documentation about possible ways of implementing authentication/authorization for

  • 0

I have been digging into Play2!Scala documentation about possible ways of implementing authentication/authorization for user requests and I must say that I am a little bit lost.
I would like to know more about how requests sent from mobiles devices are authenticated/authorized on a Play2!Scala-backed REST-service.

First of all, it seems that there are many auth-modules for Play2/scala : e.g t2v’s Play20-auth. But the thing is, these solutions are based on storing cookies on the client-side. Is that Right ? Which makes sense in a pure web perspective : requests are sent from a browser, the server can store cookies on the client etc.

Now, what if I have a native mobile application (on IOS or Android) and I am just calling a REST service backed by a Play2!Scala app. In this case, I am not using a browser, so the server can not store cookies on the client app.

Can I still use modules like t2v’s Play20-auth for authorization/authentication ?

What are the best practices for dealing with this kind of thing ?

Any help would really be appreciated,
Thanks in advance,

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T09:25:53+00:00Added an answer on June 10, 2026 at 9:25 am

    Ok, this is for authentication, then the login is separate, you can use your own system or something like openID, etc.
    The problem is how to store that the user is authenticated.

    The main idea for securing your REST service would be to use an auth token that is signed on the server side with some identifier of the user.
    It would go this way:

    1. the user enters a id/password
    2. a rest method checks this and if it’s valid, sends a token back to the phone. You store that in your app
    3. every time you make a call to your rest API you send the user id and the token and you check the token on the server.

    You have two solutions for generating and checking tokens:

    1. The token is basically the user id, concatenated with some salt of your own (whatever secret message you want) and then signed with a private key on your server. Personally I have done this with HMAC-SHA256 (using javax.crypto in my scala code).
      If someone tries to use your REST API, they won’t be able to generate the token as they do not know your private key nor the secret.
      Every time you receive a request on your REST API (3), you just recompute the hash and compare it with the one you were sent as a token.
    2. Instead of a HMAC with the user ID, another solution is to store a random number in your database for each user. This will be your token.
      Every time you receive a request, you check in the database the secret token for that user and see if it’s the same as the one from the query.

    This will create infinite tokens, so your user will never be logged out, you can add an expiration date to these solutions quite easily:

    1. if using HMAC, you put in your token (before signing) the current date. For instance, if you want a 24h session, you can do something like:

      val format = new SimpleDateFormat("d/M/yyyy");  
      isoFormat.setTimeZone(TimeZone.getTimeZone("UTC"));  
      val date = format.format(new Date());  
      val token = calculateHMAC(userID + date + secret);  
      

      for shorter/longer periods, you change the format to include more or less so that every time you generate the token to check it you fall in the same period.

    2. for the random number/database solution, you just store the date of creation of the random token, and you see if it’s in the period you like.

    If you are using an OpenID (or similar) identification from a third party, you will have to show a WebView to the user where you load the openID provider’s page, you just have to make sure that the redirect page after the authentication contains a generated token hidden somewhere (in the title for instance) and you extract it with your app code.

    This is pretty straightforward to implement yourself, but I have seen a plugin for play2 to deal with token auth:
    https://github.com/orefalo/play2-authenticitytoken (never used personaly)
    and one for stateless auth:
    https://github.com/blendlabs/play20-stateless-auth

    For the loggin bit, you don’t have to implement that, there are good modules out there for play:

    • https://github.com/joscha/play-authenticate
    • https://github.com/jaliss/securesocial
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been recently digging into Mobile Programming, I practically tried out the J2ME
I have been digging into the question for a while in StackOverflow Android get
This question has been asked before, but digging into the documentation for the various
I have been digging on facebook authentication for a week. I came across so
Have been reading about async and tasks and been attempting to convert the CopyFileEx
So I've been digging into how the stdio portion of libc is implemented and
I have been doing some research and this seems to be not possible unless
I have been digging around on this site and googling for a while now
So I am new to Microsofts reporting system, and I have been digging thru
I have been digging internet for couple days, reading very old information, that leads

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.