SlideShare a Scribd company logo
INTRODUCTION TO LARAVEL
PASSPORT
@MICHAELPEACOCK
PHP NORTH EAST, SEPTEMBER 2016
@MICHAELPEACOCK
• Co-organiser of PHP North East & Laravel North East
• Software development consultant
• Primarily serve as a consultant CTO for a number of early stage startups
INTRODUCTION
• API Authentication
• Uses oAuth
• Built on top of the PHP League oAuth 2 Server
OAUTH?
Mitchell Anicas / https://www.digitalocean.com/community/tutorials/an-introduction-to-oauth-2
SSL!
• oAuth 2 specification mandates that the authorization
server uses SSL
INSTALLATION
1. Require laravel passport
composer require laravel/passport
2. Register passport service provider in config/app.php
LaravelPassportPassportServiceProvider::class,
3. Migrate: php artisan migrate
4.Install: php artisan passport:install
SETUP
1. Add LaravelPassportHasApiTokens trait to User class
2. Call LaravelPassportPassport::routes() from
AuthServiceProvider::boot method
3. Change the driver for the api authentication guard to passport
in config/auth.php
OAUTH ROUTES OUT OF THE BOX
Method URL Description
GET /oauth/clients List clients / apps you have created
POST /oauth/clients Create a new client / app. Requires name and redirect.
PUT /oauth/clients/{id} Update client. Requires both name and redirect
DELETE /oauth/clients/{id} Delete a client.
GET /oauth/authorize Start the oAuth process, displays the accept / cancel
dialogue
POST /oauth/authorize Accept the oAuth process
POST /oauth/token Exchange a code for a token or refresh a token
GET /oauth/scopes List all scopes
GET /oauth/personal-access-tokens List all personal access tokens
POST /oauth/personal-access-tokens Request a personal access token (name and scopes
required)
DELETE /oauth/personal-access-tokens/{id} Delete a personal access token
PUBLISH VUE COMPONENTS & VIEWS
• php artisan vendor:publish --tag=passport-components
• php artisan vendor:publish --tag=passport-views
VUE INTEGRATION
Vue.component(
'passport-clients',
require('./components/passport/Clients.vue')
);
Vue.component(
'passport-authorized-clients',
require('./components/passport/AuthorizedClients.vue')
);
Vue.component(
'passport-personal-access-tokens',
require('./components/passport/PersonalAccessTokens.vue')
);
…DON’T FORGET TO GULP
• (requires an npm install first!)
USE THE VUE COMPONENTS
• <passport-clients></passport-clients>
• <passport-authorized-clients></passport-authorized-clients>
• <passport-personal-access-tokens></passport-personal-access-tokens>
DEMO 1
• VUE components
AUTHORIZE
Route::get('/connect', function () {
$query = http_build_query([
'client_id' => '3',
'redirect_uri' => 'http://…t.local/redirect',
'response_type' => 'code',
'scope' => '',
]);
return redirect('http://…t.local/oauth/authorize?'.$query);
});
EXCHANGE CODE FOR AN ACCESS TOKEN
use IlluminateHttpRequest;
Route::get('/redirect', function (Request $request) {
$http = new GuzzleHttpClient;
$response = $http->post('http://…t.local/oauth/token', [
'form_params' => [
'grant_type' => 'authorization_code',
'client_id' => '3',
'client_secret' => '9Ze2bt13P5MSmSgmFmzLdweW7BM4r8wvpnlWnxZH',
'redirect_uri' => 'http://…t.local/redirect',
'code' => $request->query->get('code'),
],
]);
return json_decode((string) $response->getBody(), true);
});
DEMO 2
• oAuth handshake
AUTHENTICATE
• Accept: application/json
• Authorization: Bearer bearer-token
REQUIRE A VALID ACCESS TOKEN
• ->middleware('auth:api')
DEFINING SCOPES
// AuthServiceProvider
LaravelPassportPassport::tokensCan([
'read' => 'Read access to user account',
'write' => 'Write access to user account’,
'email' => 'Send emails',
]);
REGISTER SCOPE MIDDLEWARE
// Http/Kernel.php Route Middleware
'scopes' => LaravelPassportHttpMiddlewareCheckScopes::class,
'scope' => LaravelPassportHttpMiddlewareCheckForAnyScope::class,
REQUIRE ANY OF A LIST OF SCOPES
->middleware('scope:read,write');
REQUIRE A NUMBER OF SCOPES
->middleware('scopes:write,email');
DEMO
• Scopes
PASSWORD GRANT
• Enabled out of the box when we did php artisan passport:install
• Can be enabled via php artisan passport:client –password
Route::get('/connect-password-grant', function () {
$http = new GuzzleHttpClient;
$response = $http->post(
'http://laravel-passport.local/oauth/token',
[
'form_params' => [
'grant_type' => 'password',
'client_id' => '2',
'client_secret' => 'xIQoQPimqpdVXQiRU81wyRa78X2mnSxSY9CD38EC',
'username' => 'mkpeacock@gmail.com',
'password' => 'password',
'scope' => 'write email',
],
]);
return json_decode((string) $response->getBody(), true);
});
DEMO
• Password grant
AUTOMATIC TOKENS FOR WEB REQUESTS
• Laravel can expose tokens (personal tokens) automatically for web users.
• Makes it easy for your application to communicate directly with its API
• Register to the web middleware group:
• LaravelPassportHttpMiddlewareCreateFreshApiToken::class,
DEMO
• Tokens for web users
CONCLUSION
• Getting an oAuth 2 server running with Laravel 5.3 is pretty easy
• The install and config is a little clunky and involves a few steps
• But with the amount of work that’s done out of the box – its all good!
THANKS, QUESTIONS?
https://bitbucket.org/mkpeacock/laravel-passport-demo

More Related Content

What's hot

Spring MVC
Spring MVCSpring MVC
Spring MVC
Aaron Schram
 
Using Change Streams to Keep Up with Your Data
Using Change Streams to Keep Up with Your DataUsing Change Streams to Keep Up with Your Data
Using Change Streams to Keep Up with Your Data
MongoDB
 
Angular - Chapter 5 - Directives
 Angular - Chapter 5 - Directives Angular - Chapter 5 - Directives
Angular - Chapter 5 - Directives
WebStackAcademy
 
REST APIs with Spring
REST APIs with SpringREST APIs with Spring
REST APIs with Spring
Joshua Long
 
Vue js for beginner
Vue js for beginner Vue js for beginner
Vue js for beginner
Chandrasekar G
 
MESIN LISTRIK.pptx
MESIN LISTRIK.pptxMESIN LISTRIK.pptx
MESIN LISTRIK.pptx
KhairulGinting1
 
Laporan 3 gelombang penuh
Laporan 3 gelombang penuhLaporan 3 gelombang penuh
Laporan 3 gelombang penuhridwan35
 
Introduzione ad angular 7/8
Introduzione ad angular 7/8Introduzione ad angular 7/8
Introduzione ad angular 7/8
Valerio Radice
 
Introdução APIs RESTful
Introdução APIs RESTfulIntrodução APIs RESTful
Introdução APIs RESTful
Douglas V. Pasqua
 
Spring MVC 3.0 Framework
Spring MVC 3.0 FrameworkSpring MVC 3.0 Framework
Django REST Framework
Django REST FrameworkDjango REST Framework
Django REST Framework
Load Impact
 
AngularJS: an introduction
AngularJS: an introductionAngularJS: an introduction
AngularJS: an introduction
Luigi De Russis
 
Sistem refrigerasi-dan-tata-udara-jilid-2
Sistem refrigerasi-dan-tata-udara-jilid-2Sistem refrigerasi-dan-tata-udara-jilid-2
Sistem refrigerasi-dan-tata-udara-jilid-2
Pangadean Sianipar
 
Spring boot - an introduction
Spring boot - an introductionSpring boot - an introduction
Spring boot - an introduction
Jonathan Holloway
 
Life Cycle hooks in VueJs
Life Cycle hooks in VueJsLife Cycle hooks in VueJs
Life Cycle hooks in VueJs
Squash Apps Pvt Ltd
 
Angular 2
Angular 2Angular 2
Angular 2
Zoubir REMILA
 
Eloquent ORM
Eloquent ORMEloquent ORM
Spring Framework - MVC
Spring Framework - MVCSpring Framework - MVC
Spring Framework - MVC
Dzmitry Naskou
 

What's hot (20)

Data Binding
Data BindingData Binding
Data Binding
 
Spring MVC
Spring MVCSpring MVC
Spring MVC
 
Using Change Streams to Keep Up with Your Data
Using Change Streams to Keep Up with Your DataUsing Change Streams to Keep Up with Your Data
Using Change Streams to Keep Up with Your Data
 
Angular - Chapter 5 - Directives
 Angular - Chapter 5 - Directives Angular - Chapter 5 - Directives
Angular - Chapter 5 - Directives
 
REST APIs with Spring
REST APIs with SpringREST APIs with Spring
REST APIs with Spring
 
Vue js for beginner
Vue js for beginner Vue js for beginner
Vue js for beginner
 
ASP.MVC Training
ASP.MVC TrainingASP.MVC Training
ASP.MVC Training
 
MESIN LISTRIK.pptx
MESIN LISTRIK.pptxMESIN LISTRIK.pptx
MESIN LISTRIK.pptx
 
Laporan 3 gelombang penuh
Laporan 3 gelombang penuhLaporan 3 gelombang penuh
Laporan 3 gelombang penuh
 
Introduzione ad angular 7/8
Introduzione ad angular 7/8Introduzione ad angular 7/8
Introduzione ad angular 7/8
 
Introdução APIs RESTful
Introdução APIs RESTfulIntrodução APIs RESTful
Introdução APIs RESTful
 
Spring MVC 3.0 Framework
Spring MVC 3.0 FrameworkSpring MVC 3.0 Framework
Spring MVC 3.0 Framework
 
Django REST Framework
Django REST FrameworkDjango REST Framework
Django REST Framework
 
AngularJS: an introduction
AngularJS: an introductionAngularJS: an introduction
AngularJS: an introduction
 
Sistem refrigerasi-dan-tata-udara-jilid-2
Sistem refrigerasi-dan-tata-udara-jilid-2Sistem refrigerasi-dan-tata-udara-jilid-2
Sistem refrigerasi-dan-tata-udara-jilid-2
 
Spring boot - an introduction
Spring boot - an introductionSpring boot - an introduction
Spring boot - an introduction
 
Life Cycle hooks in VueJs
Life Cycle hooks in VueJsLife Cycle hooks in VueJs
Life Cycle hooks in VueJs
 
Angular 2
Angular 2Angular 2
Angular 2
 
Eloquent ORM
Eloquent ORMEloquent ORM
Eloquent ORM
 
Spring Framework - MVC
Spring Framework - MVCSpring Framework - MVC
Spring Framework - MVC
 

Viewers also liked

快快樂樂用Homestead
快快樂樂用Homestead快快樂樂用Homestead
快快樂樂用Homestead
Chen Cheng-Wei
 
Laravel - 簡介與環境設定
Laravel - 簡介與環境設定Laravel - 簡介與環境設定
Laravel - 簡介與環境設定
Vincent Chi
 
Laravel - 系統全攻略
Laravel - 系統全攻略Laravel - 系統全攻略
Laravel - 系統全攻略
Vincent Chi
 
PHP也有day #27 - From apprentice to artisan 解耦合處理程序及單元測試
PHP也有day #27 - From apprentice to artisan 解耦合處理程序及單元測試PHP也有day #27 - From apprentice to artisan 解耦合處理程序及單元測試
PHP也有day #27 - From apprentice to artisan 解耦合處理程序及單元測試
亮亮 閃
 
Arduino Yún使用Http restful api控制io
Arduino Yún使用Http restful api控制ioArduino Yún使用Http restful api控制io
Arduino Yún使用Http restful api控制io
吳錫修 (ShyiShiou Wu)
 
RESTful API的设计与开发
RESTful API的设计与开发RESTful API的设计与开发
RESTful API的设计与开发
Ace Lee
 
B2B Strategy Making and Planning
B2B Strategy Making and PlanningB2B Strategy Making and Planning
B2B Strategy Making and Planning
Asia Pacific Marketing Institute
 
Business Marketing Strategy Development
Business Marketing Strategy DevelopmentBusiness Marketing Strategy Development
Business Marketing Strategy Development
Asia Pacific Marketing Institute
 
OAuthоризация и API социальных сетей
OAuthоризация и API социальных сетейOAuthоризация и API социальных сетей
OAuthоризация и API социальных сетейАртём Курапов
 
B2B Marketing Strategy
B2B Marketing StrategyB2B Marketing Strategy
B2B Marketing Strategy
Fusion Marketing Partners
 
How to develop an effective Business Development Strategy
How to develop an effective Business Development StrategyHow to develop an effective Business Development Strategy
How to develop an effective Business Development Strategy
Hein Roth
 

Viewers also liked (13)

Phinx talk
Phinx talkPhinx talk
Phinx talk
 
Omnyscope e245 march 2014 final
Omnyscope e245 march 2014 finalOmnyscope e245 march 2014 final
Omnyscope e245 march 2014 final
 
快快樂樂用Homestead
快快樂樂用Homestead快快樂樂用Homestead
快快樂樂用Homestead
 
Laravel - 簡介與環境設定
Laravel - 簡介與環境設定Laravel - 簡介與環境設定
Laravel - 簡介與環境設定
 
Laravel - 系統全攻略
Laravel - 系統全攻略Laravel - 系統全攻略
Laravel - 系統全攻略
 
PHP也有day #27 - From apprentice to artisan 解耦合處理程序及單元測試
PHP也有day #27 - From apprentice to artisan 解耦合處理程序及單元測試PHP也有day #27 - From apprentice to artisan 解耦合處理程序及單元測試
PHP也有day #27 - From apprentice to artisan 解耦合處理程序及單元測試
 
Arduino Yún使用Http restful api控制io
Arduino Yún使用Http restful api控制ioArduino Yún使用Http restful api控制io
Arduino Yún使用Http restful api控制io
 
RESTful API的设计与开发
RESTful API的设计与开发RESTful API的设计与开发
RESTful API的设计与开发
 
B2B Strategy Making and Planning
B2B Strategy Making and PlanningB2B Strategy Making and Planning
B2B Strategy Making and Planning
 
Business Marketing Strategy Development
Business Marketing Strategy DevelopmentBusiness Marketing Strategy Development
Business Marketing Strategy Development
 
OAuthоризация и API социальных сетей
OAuthоризация и API социальных сетейOAuthоризация и API социальных сетей
OAuthоризация и API социальных сетей
 
B2B Marketing Strategy
B2B Marketing StrategyB2B Marketing Strategy
B2B Marketing Strategy
 
How to develop an effective Business Development Strategy
How to develop an effective Business Development StrategyHow to develop an effective Business Development Strategy
How to develop an effective Business Development Strategy
 

Similar to An introduction to Laravel Passport

OAuth 2.0 and Library
OAuth 2.0 and LibraryOAuth 2.0 and Library
OAuth 2.0 and Library
Kenji Otsuka
 
Building @Anywhere (for TXJS)
Building @Anywhere (for TXJS)Building @Anywhere (for TXJS)
Building @Anywhere (for TXJS)danwrong
 
Mojolicious. Веб в коробке!
Mojolicious. Веб в коробке!Mojolicious. Веб в коробке!
Mojolicious. Веб в коробке!
Anatoly Sharifulin
 
How to build a High Performance PSGI/Plack Server
How to build a High Performance PSGI/Plack Server How to build a High Performance PSGI/Plack Server
How to build a High Performance PSGI/Plack Server
Masahiro Nagano
 
Silex Cheat Sheet
Silex Cheat SheetSilex Cheat Sheet
Silex Cheat Sheet
Andréia Bohner
 
Silex Cheat Sheet
Silex Cheat SheetSilex Cheat Sheet
Silex Cheat Sheet
Andréia Bohner
 
TwitterKitではじめる OAuthスピードクッキング
TwitterKitではじめる OAuthスピードクッキングTwitterKitではじめる OAuthスピードクッキング
TwitterKitではじめる OAuthスピードクッキング
Takashi Nojima
 
The dark side of the app - Todi Appy Days 2015
The dark side of the app - Todi Appy Days 2015The dark side of the app - Todi Appy Days 2015
The dark side of the app - Todi Appy Days 2015
Todi Appy Days
 
The dark side of the app
The dark side of the appThe dark side of the app
The dark side of the app
Simone Di Maulo
 
Securing RESTful Payment APIs Using OAuth 2
Securing RESTful Payment APIs Using OAuth 2Securing RESTful Payment APIs Using OAuth 2
Securing RESTful Payment APIs Using OAuth 2
Jonathan LeBlanc
 
Some OAuth love
Some OAuth loveSome OAuth love
Some OAuth love
Nicolas Blanco
 
Do you want a SDK with that API? (Nordic APIS April 2014)
Do you want a SDK with that API? (Nordic APIS April 2014)Do you want a SDK with that API? (Nordic APIS April 2014)
Do you want a SDK with that API? (Nordic APIS April 2014)Nordic APIs
 
Amazon Web Service - Basics
Amazon Web Service - BasicsAmazon Web Service - Basics
Amazon Web Service - Basics
Sang-Min Park
 
Paypal REST api ( Japanese version )
Paypal REST api ( Japanese version )Paypal REST api ( Japanese version )
Paypal REST api ( Japanese version )
Yoshi Sakai
 
Accessing APIs using OAuth on the federated (WordPress) web
Accessing APIs using OAuth on the federated (WordPress) webAccessing APIs using OAuth on the federated (WordPress) web
Accessing APIs using OAuth on the federated (WordPress) web
Felix Arntz
 
How to Create Login and Registration API in PHP.pdf
How to Create Login and Registration API in PHP.pdfHow to Create Login and Registration API in PHP.pdf
How to Create Login and Registration API in PHP.pdf
Appweb Coders
 
Securing RESTful APIs using OAuth 2 and OpenID Connect
Securing RESTful APIs using OAuth 2 and OpenID ConnectSecuring RESTful APIs using OAuth 2 and OpenID Connect
Securing RESTful APIs using OAuth 2 and OpenID Connect
Jonathan LeBlanc
 
Workshop KrakYourNet2016 - Web applications hacking Ruby on Rails example
Workshop KrakYourNet2016 - Web applications hacking Ruby on Rails example Workshop KrakYourNet2016 - Web applications hacking Ruby on Rails example
Workshop KrakYourNet2016 - Web applications hacking Ruby on Rails example
Anna Klepacka
 
Demystifying REST
Demystifying RESTDemystifying REST
Demystifying REST
Kirsten Hunter
 
NextGenPSD2 OAuth SCA Mode Security Recommendations
NextGenPSD2 OAuth SCA Mode Security RecommendationsNextGenPSD2 OAuth SCA Mode Security Recommendations
NextGenPSD2 OAuth SCA Mode Security Recommendations
Torsten Lodderstedt
 

Similar to An introduction to Laravel Passport (20)

OAuth 2.0 and Library
OAuth 2.0 and LibraryOAuth 2.0 and Library
OAuth 2.0 and Library
 
Building @Anywhere (for TXJS)
Building @Anywhere (for TXJS)Building @Anywhere (for TXJS)
Building @Anywhere (for TXJS)
 
Mojolicious. Веб в коробке!
Mojolicious. Веб в коробке!Mojolicious. Веб в коробке!
Mojolicious. Веб в коробке!
 
How to build a High Performance PSGI/Plack Server
How to build a High Performance PSGI/Plack Server How to build a High Performance PSGI/Plack Server
How to build a High Performance PSGI/Plack Server
 
Silex Cheat Sheet
Silex Cheat SheetSilex Cheat Sheet
Silex Cheat Sheet
 
Silex Cheat Sheet
Silex Cheat SheetSilex Cheat Sheet
Silex Cheat Sheet
 
TwitterKitではじめる OAuthスピードクッキング
TwitterKitではじめる OAuthスピードクッキングTwitterKitではじめる OAuthスピードクッキング
TwitterKitではじめる OAuthスピードクッキング
 
The dark side of the app - Todi Appy Days 2015
The dark side of the app - Todi Appy Days 2015The dark side of the app - Todi Appy Days 2015
The dark side of the app - Todi Appy Days 2015
 
The dark side of the app
The dark side of the appThe dark side of the app
The dark side of the app
 
Securing RESTful Payment APIs Using OAuth 2
Securing RESTful Payment APIs Using OAuth 2Securing RESTful Payment APIs Using OAuth 2
Securing RESTful Payment APIs Using OAuth 2
 
Some OAuth love
Some OAuth loveSome OAuth love
Some OAuth love
 
Do you want a SDK with that API? (Nordic APIS April 2014)
Do you want a SDK with that API? (Nordic APIS April 2014)Do you want a SDK with that API? (Nordic APIS April 2014)
Do you want a SDK with that API? (Nordic APIS April 2014)
 
Amazon Web Service - Basics
Amazon Web Service - BasicsAmazon Web Service - Basics
Amazon Web Service - Basics
 
Paypal REST api ( Japanese version )
Paypal REST api ( Japanese version )Paypal REST api ( Japanese version )
Paypal REST api ( Japanese version )
 
Accessing APIs using OAuth on the federated (WordPress) web
Accessing APIs using OAuth on the federated (WordPress) webAccessing APIs using OAuth on the federated (WordPress) web
Accessing APIs using OAuth on the federated (WordPress) web
 
How to Create Login and Registration API in PHP.pdf
How to Create Login and Registration API in PHP.pdfHow to Create Login and Registration API in PHP.pdf
How to Create Login and Registration API in PHP.pdf
 
Securing RESTful APIs using OAuth 2 and OpenID Connect
Securing RESTful APIs using OAuth 2 and OpenID ConnectSecuring RESTful APIs using OAuth 2 and OpenID Connect
Securing RESTful APIs using OAuth 2 and OpenID Connect
 
Workshop KrakYourNet2016 - Web applications hacking Ruby on Rails example
Workshop KrakYourNet2016 - Web applications hacking Ruby on Rails example Workshop KrakYourNet2016 - Web applications hacking Ruby on Rails example
Workshop KrakYourNet2016 - Web applications hacking Ruby on Rails example
 
Demystifying REST
Demystifying RESTDemystifying REST
Demystifying REST
 
NextGenPSD2 OAuth SCA Mode Security Recommendations
NextGenPSD2 OAuth SCA Mode Security RecommendationsNextGenPSD2 OAuth SCA Mode Security Recommendations
NextGenPSD2 OAuth SCA Mode Security Recommendations
 

More from Michael Peacock

Immutable Infrastructure with Packer Ansible and Terraform
Immutable Infrastructure with Packer Ansible and TerraformImmutable Infrastructure with Packer Ansible and Terraform
Immutable Infrastructure with Packer Ansible and Terraform
Michael Peacock
 
Test driven APIs with Laravel
Test driven APIs with LaravelTest driven APIs with Laravel
Test driven APIs with Laravel
Michael Peacock
 
Symfony Workflow Component - Introductory Lightning Talk
Symfony Workflow Component - Introductory Lightning TalkSymfony Workflow Component - Introductory Lightning Talk
Symfony Workflow Component - Introductory Lightning Talk
Michael Peacock
 
Alexa, lets make a skill
Alexa, lets make a skillAlexa, lets make a skill
Alexa, lets make a skill
Michael Peacock
 
Refactoring to symfony components
Refactoring to symfony componentsRefactoring to symfony components
Refactoring to symfony componentsMichael Peacock
 
Dance for the puppet master: G6 Tech Talk
Dance for the puppet master: G6 Tech TalkDance for the puppet master: G6 Tech Talk
Dance for the puppet master: G6 Tech TalkMichael Peacock
 
Powerful and flexible templates with Twig
Powerful and flexible templates with Twig Powerful and flexible templates with Twig
Powerful and flexible templates with Twig Michael Peacock
 
Introduction to OOP with PHP
Introduction to OOP with PHPIntroduction to OOP with PHP
Introduction to OOP with PHPMichael Peacock
 
Phpne august-2012-symfony-components-friends
Phpne august-2012-symfony-components-friendsPhpne august-2012-symfony-components-friends
Phpne august-2012-symfony-components-friendsMichael Peacock
 
Evolution of a big data project
Evolution of a big data projectEvolution of a big data project
Evolution of a big data projectMichael Peacock
 
Real time voice call integration - Confoo 2012
Real time voice call integration - Confoo 2012Real time voice call integration - Confoo 2012
Real time voice call integration - Confoo 2012Michael Peacock
 
Dealing with Continuous Data Processing, ConFoo 2012
Dealing with Continuous Data Processing, ConFoo 2012Dealing with Continuous Data Processing, ConFoo 2012
Dealing with Continuous Data Processing, ConFoo 2012Michael Peacock
 
Data at Scale - Michael Peacock, Cloud Connect 2012
Data at Scale - Michael Peacock, Cloud Connect 2012Data at Scale - Michael Peacock, Cloud Connect 2012
Data at Scale - Michael Peacock, Cloud Connect 2012Michael Peacock
 
PHP & Twilio
PHP & TwilioPHP & Twilio
PHP & Twilio
Michael Peacock
 
PHP Continuous Data Processing
PHP Continuous Data ProcessingPHP Continuous Data Processing
PHP Continuous Data ProcessingMichael Peacock
 
PHP North East Registry Pattern
PHP North East Registry PatternPHP North East Registry Pattern
PHP North East Registry PatternMichael Peacock
 
PHP North East - Registry Design Pattern
PHP North East - Registry Design PatternPHP North East - Registry Design Pattern
PHP North East - Registry Design PatternMichael Peacock
 
Supermondays: Jenkins CI lightning talk
Supermondays: Jenkins CI lightning talkSupermondays: Jenkins CI lightning talk
Supermondays: Jenkins CI lightning talk
Michael Peacock
 

More from Michael Peacock (20)

Immutable Infrastructure with Packer Ansible and Terraform
Immutable Infrastructure with Packer Ansible and TerraformImmutable Infrastructure with Packer Ansible and Terraform
Immutable Infrastructure with Packer Ansible and Terraform
 
Test driven APIs with Laravel
Test driven APIs with LaravelTest driven APIs with Laravel
Test driven APIs with Laravel
 
Symfony Workflow Component - Introductory Lightning Talk
Symfony Workflow Component - Introductory Lightning TalkSymfony Workflow Component - Introductory Lightning Talk
Symfony Workflow Component - Introductory Lightning Talk
 
Alexa, lets make a skill
Alexa, lets make a skillAlexa, lets make a skill
Alexa, lets make a skill
 
Refactoring to symfony components
Refactoring to symfony componentsRefactoring to symfony components
Refactoring to symfony components
 
Dance for the puppet master: G6 Tech Talk
Dance for the puppet master: G6 Tech TalkDance for the puppet master: G6 Tech Talk
Dance for the puppet master: G6 Tech Talk
 
Powerful and flexible templates with Twig
Powerful and flexible templates with Twig Powerful and flexible templates with Twig
Powerful and flexible templates with Twig
 
Introduction to OOP with PHP
Introduction to OOP with PHPIntroduction to OOP with PHP
Introduction to OOP with PHP
 
Vagrant
VagrantVagrant
Vagrant
 
Phpne august-2012-symfony-components-friends
Phpne august-2012-symfony-components-friendsPhpne august-2012-symfony-components-friends
Phpne august-2012-symfony-components-friends
 
Evolution of a big data project
Evolution of a big data projectEvolution of a big data project
Evolution of a big data project
 
Real time voice call integration - Confoo 2012
Real time voice call integration - Confoo 2012Real time voice call integration - Confoo 2012
Real time voice call integration - Confoo 2012
 
Dealing with Continuous Data Processing, ConFoo 2012
Dealing with Continuous Data Processing, ConFoo 2012Dealing with Continuous Data Processing, ConFoo 2012
Dealing with Continuous Data Processing, ConFoo 2012
 
Data at Scale - Michael Peacock, Cloud Connect 2012
Data at Scale - Michael Peacock, Cloud Connect 2012Data at Scale - Michael Peacock, Cloud Connect 2012
Data at Scale - Michael Peacock, Cloud Connect 2012
 
Supermondays twilio
Supermondays twilioSupermondays twilio
Supermondays twilio
 
PHP & Twilio
PHP & TwilioPHP & Twilio
PHP & Twilio
 
PHP Continuous Data Processing
PHP Continuous Data ProcessingPHP Continuous Data Processing
PHP Continuous Data Processing
 
PHP North East Registry Pattern
PHP North East Registry PatternPHP North East Registry Pattern
PHP North East Registry Pattern
 
PHP North East - Registry Design Pattern
PHP North East - Registry Design PatternPHP North East - Registry Design Pattern
PHP North East - Registry Design Pattern
 
Supermondays: Jenkins CI lightning talk
Supermondays: Jenkins CI lightning talkSupermondays: Jenkins CI lightning talk
Supermondays: Jenkins CI lightning talk
 

Recently uploaded

Bridging the Digital Gap Brad Spiegel Macon, GA Initiative.pptx
Bridging the Digital Gap Brad Spiegel Macon, GA Initiative.pptxBridging the Digital Gap Brad Spiegel Macon, GA Initiative.pptx
Bridging the Digital Gap Brad Spiegel Macon, GA Initiative.pptx
Brad Spiegel Macon GA
 
The+Prospects+of+E-Commerce+in+China.pptx
The+Prospects+of+E-Commerce+in+China.pptxThe+Prospects+of+E-Commerce+in+China.pptx
The+Prospects+of+E-Commerce+in+China.pptx
laozhuseo02
 
Internet-Security-Safeguarding-Your-Digital-World (1).pptx
Internet-Security-Safeguarding-Your-Digital-World (1).pptxInternet-Security-Safeguarding-Your-Digital-World (1).pptx
Internet-Security-Safeguarding-Your-Digital-World (1).pptx
VivekSinghShekhawat2
 
History+of+E-commerce+Development+in+China-www.cfye-commerce.shop
History+of+E-commerce+Development+in+China-www.cfye-commerce.shopHistory+of+E-commerce+Development+in+China-www.cfye-commerce.shop
History+of+E-commerce+Development+in+China-www.cfye-commerce.shop
laozhuseo02
 
test test test test testtest test testtest test testtest test testtest test ...
test test  test test testtest test testtest test testtest test testtest test ...test test  test test testtest test testtest test testtest test testtest test ...
test test test test testtest test testtest test testtest test testtest test ...
Arif0071
 
How to Use Contact Form 7 Like a Pro.pptx
How to Use Contact Form 7 Like a Pro.pptxHow to Use Contact Form 7 Like a Pro.pptx
How to Use Contact Form 7 Like a Pro.pptx
Gal Baras
 
Multi-cluster Kubernetes Networking- Patterns, Projects and Guidelines
Multi-cluster Kubernetes Networking- Patterns, Projects and GuidelinesMulti-cluster Kubernetes Networking- Patterns, Projects and Guidelines
Multi-cluster Kubernetes Networking- Patterns, Projects and Guidelines
Sanjeev Rampal
 
guildmasters guide to ravnica Dungeons & Dragons 5...
guildmasters guide to ravnica Dungeons & Dragons 5...guildmasters guide to ravnica Dungeons & Dragons 5...
guildmasters guide to ravnica Dungeons & Dragons 5...
Rogerio Filho
 
APNIC Foundation, presented by Ellisha Heppner at the PNG DNS Forum 2024
APNIC Foundation, presented by Ellisha Heppner at the PNG DNS Forum 2024APNIC Foundation, presented by Ellisha Heppner at the PNG DNS Forum 2024
APNIC Foundation, presented by Ellisha Heppner at the PNG DNS Forum 2024
APNIC
 
JAVIER LASA-EXPERIENCIA digital 1986-2024.pdf
JAVIER LASA-EXPERIENCIA digital 1986-2024.pdfJAVIER LASA-EXPERIENCIA digital 1986-2024.pdf
JAVIER LASA-EXPERIENCIA digital 1986-2024.pdf
Javier Lasa
 
This 7-second Brain Wave Ritual Attracts Money To You.!
This 7-second Brain Wave Ritual Attracts Money To You.!This 7-second Brain Wave Ritual Attracts Money To You.!
This 7-second Brain Wave Ritual Attracts Money To You.!
nirahealhty
 
原版仿制(uob毕业证书)英国伯明翰大学毕业证本科学历证书原版一模一样
原版仿制(uob毕业证书)英国伯明翰大学毕业证本科学历证书原版一模一样原版仿制(uob毕业证书)英国伯明翰大学毕业证本科学历证书原版一模一样
原版仿制(uob毕业证书)英国伯明翰大学毕业证本科学历证书原版一模一样
3ipehhoa
 
Latest trends in computer networking.pptx
Latest trends in computer networking.pptxLatest trends in computer networking.pptx
Latest trends in computer networking.pptx
JungkooksNonexistent
 
Comptia N+ Standard Networking lesson guide
Comptia N+ Standard Networking lesson guideComptia N+ Standard Networking lesson guide
Comptia N+ Standard Networking lesson guide
GTProductions1
 
BASIC C++ lecture NOTE C++ lecture 3.pptx
BASIC C++ lecture NOTE C++ lecture 3.pptxBASIC C++ lecture NOTE C++ lecture 3.pptx
BASIC C++ lecture NOTE C++ lecture 3.pptx
natyesu
 
一比一原版(SLU毕业证)圣路易斯大学毕业证成绩单专业办理
一比一原版(SLU毕业证)圣路易斯大学毕业证成绩单专业办理一比一原版(SLU毕业证)圣路易斯大学毕业证成绩单专业办理
一比一原版(SLU毕业证)圣路易斯大学毕业证成绩单专业办理
keoku
 
一比一原版(LBS毕业证)伦敦商学院毕业证成绩单专业办理
一比一原版(LBS毕业证)伦敦商学院毕业证成绩单专业办理一比一原版(LBS毕业证)伦敦商学院毕业证成绩单专业办理
一比一原版(LBS毕业证)伦敦商学院毕业证成绩单专业办理
eutxy
 
1比1复刻(bath毕业证书)英国巴斯大学毕业证学位证原版一模一样
1比1复刻(bath毕业证书)英国巴斯大学毕业证学位证原版一模一样1比1复刻(bath毕业证书)英国巴斯大学毕业证学位证原版一模一样
1比1复刻(bath毕业证书)英国巴斯大学毕业证学位证原版一模一样
3ipehhoa
 
一比一原版(CSU毕业证)加利福尼亚州立大学毕业证成绩单专业办理
一比一原版(CSU毕业证)加利福尼亚州立大学毕业证成绩单专业办理一比一原版(CSU毕业证)加利福尼亚州立大学毕业证成绩单专业办理
一比一原版(CSU毕业证)加利福尼亚州立大学毕业证成绩单专业办理
ufdana
 
急速办(bedfordhire毕业证书)英国贝德福特大学毕业证成绩单原版一模一样
急速办(bedfordhire毕业证书)英国贝德福特大学毕业证成绩单原版一模一样急速办(bedfordhire毕业证书)英国贝德福特大学毕业证成绩单原版一模一样
急速办(bedfordhire毕业证书)英国贝德福特大学毕业证成绩单原版一模一样
3ipehhoa
 

Recently uploaded (20)

Bridging the Digital Gap Brad Spiegel Macon, GA Initiative.pptx
Bridging the Digital Gap Brad Spiegel Macon, GA Initiative.pptxBridging the Digital Gap Brad Spiegel Macon, GA Initiative.pptx
Bridging the Digital Gap Brad Spiegel Macon, GA Initiative.pptx
 
The+Prospects+of+E-Commerce+in+China.pptx
The+Prospects+of+E-Commerce+in+China.pptxThe+Prospects+of+E-Commerce+in+China.pptx
The+Prospects+of+E-Commerce+in+China.pptx
 
Internet-Security-Safeguarding-Your-Digital-World (1).pptx
Internet-Security-Safeguarding-Your-Digital-World (1).pptxInternet-Security-Safeguarding-Your-Digital-World (1).pptx
Internet-Security-Safeguarding-Your-Digital-World (1).pptx
 
History+of+E-commerce+Development+in+China-www.cfye-commerce.shop
History+of+E-commerce+Development+in+China-www.cfye-commerce.shopHistory+of+E-commerce+Development+in+China-www.cfye-commerce.shop
History+of+E-commerce+Development+in+China-www.cfye-commerce.shop
 
test test test test testtest test testtest test testtest test testtest test ...
test test  test test testtest test testtest test testtest test testtest test ...test test  test test testtest test testtest test testtest test testtest test ...
test test test test testtest test testtest test testtest test testtest test ...
 
How to Use Contact Form 7 Like a Pro.pptx
How to Use Contact Form 7 Like a Pro.pptxHow to Use Contact Form 7 Like a Pro.pptx
How to Use Contact Form 7 Like a Pro.pptx
 
Multi-cluster Kubernetes Networking- Patterns, Projects and Guidelines
Multi-cluster Kubernetes Networking- Patterns, Projects and GuidelinesMulti-cluster Kubernetes Networking- Patterns, Projects and Guidelines
Multi-cluster Kubernetes Networking- Patterns, Projects and Guidelines
 
guildmasters guide to ravnica Dungeons & Dragons 5...
guildmasters guide to ravnica Dungeons & Dragons 5...guildmasters guide to ravnica Dungeons & Dragons 5...
guildmasters guide to ravnica Dungeons & Dragons 5...
 
APNIC Foundation, presented by Ellisha Heppner at the PNG DNS Forum 2024
APNIC Foundation, presented by Ellisha Heppner at the PNG DNS Forum 2024APNIC Foundation, presented by Ellisha Heppner at the PNG DNS Forum 2024
APNIC Foundation, presented by Ellisha Heppner at the PNG DNS Forum 2024
 
JAVIER LASA-EXPERIENCIA digital 1986-2024.pdf
JAVIER LASA-EXPERIENCIA digital 1986-2024.pdfJAVIER LASA-EXPERIENCIA digital 1986-2024.pdf
JAVIER LASA-EXPERIENCIA digital 1986-2024.pdf
 
This 7-second Brain Wave Ritual Attracts Money To You.!
This 7-second Brain Wave Ritual Attracts Money To You.!This 7-second Brain Wave Ritual Attracts Money To You.!
This 7-second Brain Wave Ritual Attracts Money To You.!
 
原版仿制(uob毕业证书)英国伯明翰大学毕业证本科学历证书原版一模一样
原版仿制(uob毕业证书)英国伯明翰大学毕业证本科学历证书原版一模一样原版仿制(uob毕业证书)英国伯明翰大学毕业证本科学历证书原版一模一样
原版仿制(uob毕业证书)英国伯明翰大学毕业证本科学历证书原版一模一样
 
Latest trends in computer networking.pptx
Latest trends in computer networking.pptxLatest trends in computer networking.pptx
Latest trends in computer networking.pptx
 
Comptia N+ Standard Networking lesson guide
Comptia N+ Standard Networking lesson guideComptia N+ Standard Networking lesson guide
Comptia N+ Standard Networking lesson guide
 
BASIC C++ lecture NOTE C++ lecture 3.pptx
BASIC C++ lecture NOTE C++ lecture 3.pptxBASIC C++ lecture NOTE C++ lecture 3.pptx
BASIC C++ lecture NOTE C++ lecture 3.pptx
 
一比一原版(SLU毕业证)圣路易斯大学毕业证成绩单专业办理
一比一原版(SLU毕业证)圣路易斯大学毕业证成绩单专业办理一比一原版(SLU毕业证)圣路易斯大学毕业证成绩单专业办理
一比一原版(SLU毕业证)圣路易斯大学毕业证成绩单专业办理
 
一比一原版(LBS毕业证)伦敦商学院毕业证成绩单专业办理
一比一原版(LBS毕业证)伦敦商学院毕业证成绩单专业办理一比一原版(LBS毕业证)伦敦商学院毕业证成绩单专业办理
一比一原版(LBS毕业证)伦敦商学院毕业证成绩单专业办理
 
1比1复刻(bath毕业证书)英国巴斯大学毕业证学位证原版一模一样
1比1复刻(bath毕业证书)英国巴斯大学毕业证学位证原版一模一样1比1复刻(bath毕业证书)英国巴斯大学毕业证学位证原版一模一样
1比1复刻(bath毕业证书)英国巴斯大学毕业证学位证原版一模一样
 
一比一原版(CSU毕业证)加利福尼亚州立大学毕业证成绩单专业办理
一比一原版(CSU毕业证)加利福尼亚州立大学毕业证成绩单专业办理一比一原版(CSU毕业证)加利福尼亚州立大学毕业证成绩单专业办理
一比一原版(CSU毕业证)加利福尼亚州立大学毕业证成绩单专业办理
 
急速办(bedfordhire毕业证书)英国贝德福特大学毕业证成绩单原版一模一样
急速办(bedfordhire毕业证书)英国贝德福特大学毕业证成绩单原版一模一样急速办(bedfordhire毕业证书)英国贝德福特大学毕业证成绩单原版一模一样
急速办(bedfordhire毕业证书)英国贝德福特大学毕业证成绩单原版一模一样
 

An introduction to Laravel Passport

Editor's Notes

  1. oAuth has practically become the defacto mechanism for API authentication, and provides a secure mechanism for users to authorise third party developers to programatically access their accounts on certain web services – such as social networks, CRM systems, or other web services – without having to enter their password directly on these third party websites. Because oAuth uses tokens which are completely separate to a users standard login credentials, the user is in control, and can revoke tokens.
  2. Tokens are passed around in plain text, as such the oAuth 2 specification mandates that the authorization server uses SSL to encrypt traffic.
  3. The installation is quite involved with Laravel Passport, as in addition to its own code, it needs to be registered within your application and has a number of setup steps beyond this slide. First, we require the component via composer, then we need to register the passport service provider. Next we need to migrate our database (a nice feature of Laravel 5.3 is that it can look in a number of migration directories, so there is no need to publish migrations from the package). Next we need to run passport:install, this will create a public / private keypair for API authentication, and then it will create two default oAuth clients/apps, one for personal authentication (where we as users authenticate directly with the API, as opposed to authorizing a third party developer) and a password authentication client which lets us exchange a username and password for a token – this again is us authenticating directly, not via a third party, and would be used for your own mobile apps, etc.
  4. First we need to tell the User model that it has API tokens, with the appropriate trait. Next we call the Passport routes method in our auth service provider, this registers our oAuth and related routes Finally we tell Laravel that for API authentication we want to use the passport driver, which will defer to checking oAuth tokens
  5. There are a range of different routes that come out of the box with Passport. /oauth/clients let us create edit and delete clients. A client is something a third party developer will create, and tokens are linked to a client. /oauth/authorize is the request for authorizing a client to access the API on our behalf, and will ask us to confirm, giving access to specific scopes, or cancel. On acceptance we are redirected back to our app. When redirected our app then needs to call the /oauth/token endpoint to exchange an authorization code for an access token, or to refresh an access token using the refresh token. There is a /oauth/scopes endpoint which lists scopes that are registered in the aplication And finally there are personal access tokens which are tokens not linked to a client (i.e. us directly talking to the API)
  6. Passport provides some Vue components which allow us to manage clients and personal access tokens, and revoke access tokens without writing any code! In order to use these we need to publish the Vue components from the package. Passport also provides us with some templates for the Approve this client screen. We don’t need to publish these, but if we do, we can customise the look and feel if we wish.
  7. In order to use the Vue components we need to register them in our app.js file.
  8. In order for these components to be included we need to run gulp, which of course requires an npm install.
  9. Finally, in order to use the vue components, we just add the above tags into a page where we wish to use them. I’ve just put them in the default Laravel authenticated welcome screen.
  10. Uncomment Passport::routes() in AuthServiceProvider
  11. Uncomment /connect and /redirect from web.php Login and visit /connect
  12. Demo: api/user
  13. Either scope will be fine
  14. Uncomment read/write scope in routes/api.php Uncomment write email in routes/web.php Re-get token Cocoarest client demo
  15. ONLY works on the relevant password client (other oAuth clients will reject it)
  16. Uncomment connect password grant in routes/web.php
  17. Uncomment \Laravel\Passport\Http\Middleware\CreateFreshApiToken::class, in Kernel.php middleware groups