I write Restful using 'Laravel'. I do it all for the first time and I don’t really understand that yes how. I have an application (Android), and I need something that my restful could receive requests only from this application. For this, as I understand it, you need to somehow authenticate my application, but I don’t understand how to do it. I'm still new to programming, so forgive me if my question turned out to be stupid.

    2 answers 2

    Starting from 5.2, it is standardly supported to set a unique api key for each user:

    Jacob Bennett has written the API token Authentication in Laravel 5.2.

    Check out the short notice:

    • Add an api_token column to your users table. 60-character string, unique. Instead of using the auth middleware in your route definition, use the auth: api middleware.
    • In your API routes, use Auth :: guard ('api') -> user () to get your user route instead of Auth :: user (). This is what you’ve been asking you to use. And since it's stateless, you will need this API token set; one successful request will not affect the next request.

    For adding on the Android side, for example through Retrofit, try to explicitly specify @Query or so Retrofit 2 - How to Add Query Parameters to Every Request

      Good day. I would recommend you use JWT token. http://jwt.io/

      In order to tell your application that you are an authorized user.

      We head to HEADERS: {X-AUTH-TOKEN: JWT} GET / user / {id} / friends

      To get token

      POST / token {username: "", password: ""}

      Finished project that will help you figure out https://github.com/tymondesigns/jwt-auth

      Successful development!