Building an API for 3rd party applications
Mohamed Said has written a nice tutorial about how to build an API for 3rd party applications:
Introduction
APIs are cool, & laravel can handle all the coolness you may desire. Here we talk about building an API for third party applications and allowing them to communicate with your application on behalf of users.
Planning ahead
Our application gives third-party applications the ability to read/write data, we only need the applications we know about to be able to connect, we also need to be able to deactivate an application at any point of time, here's a list of all the specs:
Issue an application authentication token.
Deactivate an application so that it may not make requests.
Allow our users to log in from a 3rd party app.
Allow our users to log out from an app.
New Laravel installation
For the purpose of this post we're going to install a fresh copy of laravel to run our project "Valhalla":
composer create-project laravel/laravel valhalla
Preparing files
Update app/Http/routes.php:
$router->group(['prefix' => 'api/v1'], function ($router) { // Applications Authentication... $router->post('/auth/app', 'Api\AuthController@authenticateApp'); // Users Authentication... $router->post('/auth/user', 'Api\AuthController@authenticateUser')->middleware('auth.api.app'); $router->post('/auth/user/logout', 'Api\AuthController@logoutUser')->middleware('auth.api.user'); // Testing routes...
Link:
This post is submitted by our members. Submit a new post.
Tags: Tutorials Laravel 5 Laravel 5.1 Intermediate Laravel 5.2