Api Restful Lockable 5.2

Asked

Viewed 499 times

1

Hello,

I am trying to create an api in Laravel 5.2

what I’m trying to do is this:

1 - continue using default auth system for web user.

2 - create an api for users of an application.

I am using the method: auth:api, but with this method I am obliged to know the user token and what I wanted is the following in the api the user type the user and password dai with this would return me the token and he could access their pages or entries etc...

my route.php

Route::get('/', function () {
    return redirect('/home');
});

Route::auth();

Route::get('/home', 'HomeController@index');

Route::group(['prefix' => 'api/v1', 'middleware' => 'auth:api'], function () {
    Route::get('/', function () {
        return Auth::guard('api')->user();
    });
});

thank you

  • 1

    Have you thought about using jwt? See here: https://github.com/code-sample/laravel-jwt-auth

  • @Evert thank you so much for the link, apparently this all ok. Thank you

2 answers

1

To get the initial token, you need to create a route outside the group that uses middleware auth.api

a simple route as api/authenticate that receives the user data and returns the token, if the login is done successfully

-1

  • 3

    Could you describe the solution or copy part of the link explanation to your answer?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.