🚀 DevOps & SRE Certification Program 📅 Starting: 1st of Every Month 🤝 +91 8409492687 🔍 Contact@DevOpsSchool.com

Upgrade & Secure Your Future with DevOps, SRE, DevSecOps, MLOps!

We spend hours on Instagram and YouTube and waste money on coffee and fast food, but won’t spend 30 minutes a day learning skills to boost our careers.
Master in DevOps, SRE, DevSecOps & MLOps!

Learn from Guru Rajesh Kumar and double your salary in just one year.


Get Started Now!

Creating a OAuth 2.0 Protected REST API In Laravel

oauth-2-0-protected-rest-ap
  • Download and install WAMP or XAMPP Server
  • Download and install composer
  • Open Gitbash and Set the composer
  • composer global require “laravel/installer”
  • Create a new Laravel Project
  • Refer following code
composer create-project laravel/laravel <Project Name> "5.5.*" --prefer-dist
# Move to new project directory: <Project Name>
cd <Project Name>
Install Passport:
----------------
composer require paragonie/random_compat:2.*
composer require laravel/passport "4.0.*"
$ php artisan migrate
Migrating: 2014_10_12_000000_create_users_table
Migrated: 2014_10_12_000000_create_users_table
Migrating: 2014_10_12_100000_create_password_resets_table
Migrated: 2014_10_12_100000_create_password_resets_table
Migrating: 2016_06_01_000001_create_oauth_auth_codes_table
Migrated: 2016_06_01_000001_create_oauth_auth_codes_table
Migrating: 2016_06_01_000002_create_oauth_access_tokens_table
Migrated: 2016_06_01_000002_create_oauth_access_tokens_table
Migrating: 2016_06_01_000003_create_oauth_refresh_tokens_table
Migrated: 2016_06_01_000003_create_oauth_refresh_tokens_table
Migrating: 2016_06_01_000004_create_oauth_clients_table
Migrated: 2016_06_01_000004_create_oauth_clients_table
Migrating: 2016_06_01_000005_create_oauth_personal_access_clients_table
Migrated: 2016_06_01_000005_create_oauth_personal_access_clients_table
$ php artisan passport:install
Encryption keys generated successfully.
Personal access client created successfully.
Client ID: 1
Client Secret: vMSs3J7dxU1RLCzSaeTMjARIhY3I3C3nIumxAaty
Password grant client created successfully.
Client ID: 2
Client Secret: grK9hSGJS1jhKMGKGxUia4D6vSRGxB313FIruBsI
php artisan make:controller API/TestController --resource
php artisan make:model model/TestModel
$ php artisan make:migration create_test_table --create=tests
Created Migration: 2019_09_24_090439_create_test_table
$ php artisan make:seeder TestTableSeeder
Seeder created successfully.
$ php artisan make:factory TestFactory
Factory created successfully.
$ php artisan migrate
Migrating: 2019_09_24_090439_create_test_table
Migrated: 2019_09_24_090439_create_test_table
$ php artisan db:seed
Seeding: TestTableSeeder
Make the Changes similar to the commit given below in your project:
--------------------------------------------------------------------
https://bitbucket.org/cotocusdevelopers/sp-microserivce-starter-kit/commits/a9276ae7c74e9568e87098ba6955e7659e2c828a
Test If Everything is working fine:
-----------------------------------
Refer to the link given below for steps to test your api:
https://bitbucket.org/cotocusdevelopers/sp-microserivce-starter-kit/src/master/README.md

How to make a Machine to Machine call from one microservice to the other: Using Guzzle

use GuzzleHttp\Exception\GuzzleException;
use GuzzleHttp\Exception\RequestException;
use GuzzleHttp\Client;
public static function getTestApiRespone(string $access_token) {
try {
$http = new Client(); //GuzzleHttp\Client
$response = $http->get(
'http://surgery-planet-quote-booking/api/test',
[
'headers' => [
'Accept' => 'html',
'Authorization' => 'Bearer ' . $access_token
]
]
);
return $response->getBody();
} catch (RequestException $e) {
/*Debugbar::error('Inside Helper->getQuoteBookingForm()->CATCH BLOCK');
Debugbar::error($e);
Debugbar::error($e->getMessage());
Debugbar::error('Exiting from Helper->getQuoteBookingForm()->CATCH BLOCK');*/
return $e->getResponse()->getStatusCode() . ': ' . $e->getMessage();
}
}
public static function getTestApiResponeWithAuth() {
try {
$http = new Client(); //GuzzleHttp\Client
$response = $http->post(
'http://surgery-planet-quote-booking/oauth/token',
[
'form_params' => [
'grant_type' => 'client_credentials',
'client_id' => '6',
'client_secret' => 'YoaLmACopaMUTZsmB4fsxtn6OEMGQj7FqZsbazwQ',
'redirect_uri' => '',
],
]
);
$array = $response->getBody()->getContents();
$json = json_decode($array, true);
$collection = collect($json);
$access_token = $collection->get('access_token');
return Helper::getTestApiRespone($access_token);
} catch (RequestException $e) {
/*Debugbar::error('Inside Helper->getQuoteBookingFormWithAuth()->CATCH BLOCK');
Debugbar::error($e);
Debugbar::error($e->getMessage());
Debugbar::error('Exiting from Helper->getQuoteBookingFormWithAuth()->CATCH BLOCK');*/
return $e->getResponse()->getStatusCode() . ': ' . $e->getMessage();
}
}

Certification Courses

DevOpsSchool has introduced a series of professional certification courses designed to enhance your skills and expertise in cutting-edge technologies and methodologies. Whether you are aiming to excel in development, security, or operations, these certifications provide a comprehensive learning experience. Explore the following programs:

DevOps Certification, SRE Certification, and DevSecOps Certification by DevOpsSchool

Explore our DevOps Certification, SRE Certification, and DevSecOps Certification programs at DevOpsSchool. Gain the expertise needed to excel in your career with hands-on training and globally recognized certifications.