SlideShare una empresa de Scribd logo
1 de 30
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

Más contenido relacionado

La actualidad más candente

API Development with Laravel
API Development with LaravelAPI Development with Laravel
API Development with LaravelMichael Peacock
 
PHP Powerpoint -- Teach PHP with this
PHP Powerpoint -- Teach PHP with thisPHP Powerpoint -- Teach PHP with this
PHP Powerpoint -- Teach PHP with thisIan Macali
 
Java Spring framework, Dependency Injection, DI, IoC, Inversion of Control
Java Spring framework, Dependency Injection, DI, IoC, Inversion of ControlJava Spring framework, Dependency Injection, DI, IoC, Inversion of Control
Java Spring framework, Dependency Injection, DI, IoC, Inversion of ControlArjun Thakur
 
Bypass file upload restrictions
Bypass file upload restrictionsBypass file upload restrictions
Bypass file upload restrictionsMukesh k.r
 
HTTP Request Header and HTTP Status Code
HTTP Request Header and HTTP Status CodeHTTP Request Header and HTTP Status Code
HTTP Request Header and HTTP Status CodeAbhishek L.R
 
Testing Spring Boot application in post-JUnit 4 world
Testing Spring Boot application in post-JUnit 4 worldTesting Spring Boot application in post-JUnit 4 world
Testing Spring Boot application in post-JUnit 4 worldYura Nosenko
 
C# ASP.NET WEB API APPLICATION DEVELOPMENT
C# ASP.NET WEB API APPLICATION DEVELOPMENTC# ASP.NET WEB API APPLICATION DEVELOPMENT
C# ASP.NET WEB API APPLICATION DEVELOPMENTDr. Awase Khirni Syed
 
OAuth2 and Spring Security
OAuth2 and Spring SecurityOAuth2 and Spring Security
OAuth2 and Spring SecurityOrest Ivasiv
 
Introduction to advanced python
Introduction to advanced pythonIntroduction to advanced python
Introduction to advanced pythonCharles-Axel Dein
 
Java servlet life cycle - methods ppt
Java servlet life cycle - methods pptJava servlet life cycle - methods ppt
Java servlet life cycle - methods pptkamal kotecha
 
Domain Driven Design Made Functional with Python
Domain Driven Design Made Functional with Python Domain Driven Design Made Functional with Python
Domain Driven Design Made Functional with Python Jean Carlo Machado
 
Introduction to laravel framework
Introduction to laravel frameworkIntroduction to laravel framework
Introduction to laravel frameworkAhmad Fatoni
 
SQLAlchemy Primer
SQLAlchemy PrimerSQLAlchemy Primer
SQLAlchemy Primer泰 増田
 
02 - [ASP.NET Core] ASP.NET Core MVC
02 - [ASP.NET Core] ASP.NET Core MVC 02 - [ASP.NET Core] ASP.NET Core MVC
02 - [ASP.NET Core] ASP.NET Core MVC Cellenza
 

La actualidad más candente (20)

REST API Authentication Methods.pdf
REST API Authentication Methods.pdfREST API Authentication Methods.pdf
REST API Authentication Methods.pdf
 
API Development with Laravel
API Development with LaravelAPI Development with Laravel
API Development with Laravel
 
PHP Powerpoint -- Teach PHP with this
PHP Powerpoint -- Teach PHP with thisPHP Powerpoint -- Teach PHP with this
PHP Powerpoint -- Teach PHP with this
 
Java Spring framework, Dependency Injection, DI, IoC, Inversion of Control
Java Spring framework, Dependency Injection, DI, IoC, Inversion of ControlJava Spring framework, Dependency Injection, DI, IoC, Inversion of Control
Java Spring framework, Dependency Injection, DI, IoC, Inversion of Control
 
Bypass file upload restrictions
Bypass file upload restrictionsBypass file upload restrictions
Bypass file upload restrictions
 
Java 8 streams
Java 8 streamsJava 8 streams
Java 8 streams
 
HTTP Request Header and HTTP Status Code
HTTP Request Header and HTTP Status CodeHTTP Request Header and HTTP Status Code
HTTP Request Header and HTTP Status Code
 
Testing Spring Boot application in post-JUnit 4 world
Testing Spring Boot application in post-JUnit 4 worldTesting Spring Boot application in post-JUnit 4 world
Testing Spring Boot application in post-JUnit 4 world
 
C# ASP.NET WEB API APPLICATION DEVELOPMENT
C# ASP.NET WEB API APPLICATION DEVELOPMENTC# ASP.NET WEB API APPLICATION DEVELOPMENT
C# ASP.NET WEB API APPLICATION DEVELOPMENT
 
OAuth2 and Spring Security
OAuth2 and Spring SecurityOAuth2 and Spring Security
OAuth2 and Spring Security
 
Lesson 5 php operators
Lesson 5   php operatorsLesson 5   php operators
Lesson 5 php operators
 
Dropwizard
DropwizardDropwizard
Dropwizard
 
Introduction to advanced python
Introduction to advanced pythonIntroduction to advanced python
Introduction to advanced python
 
Java servlet life cycle - methods ppt
Java servlet life cycle - methods pptJava servlet life cycle - methods ppt
Java servlet life cycle - methods ppt
 
Domain Driven Design Made Functional with Python
Domain Driven Design Made Functional with Python Domain Driven Design Made Functional with Python
Domain Driven Design Made Functional with Python
 
Introduction to laravel framework
Introduction to laravel frameworkIntroduction to laravel framework
Introduction to laravel framework
 
Spring annotation
Spring annotationSpring annotation
Spring annotation
 
SQLAlchemy Primer
SQLAlchemy PrimerSQLAlchemy Primer
SQLAlchemy Primer
 
02 - [ASP.NET Core] ASP.NET Core MVC
02 - [ASP.NET Core] ASP.NET Core MVC 02 - [ASP.NET Core] ASP.NET Core MVC
02 - [ASP.NET Core] ASP.NET Core MVC
 
Control Structures In Php 2
Control Structures In Php 2Control Structures In Php 2
Control Structures In Php 2
 

Destacado

快快樂樂用Homestead
快快樂樂用Homestead快快樂樂用Homestead
快快樂樂用HomesteadChen 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
 
OAuthоризация и API социальных сетей
OAuthоризация и API социальных сетейOAuthоризация и API социальных сетей
OAuthоризация и API социальных сетейАртём Курапов
 
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 StrategyHein Roth
 

Destacado (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 a An introduction to Laravel Passport

OAuth 2.0 and Library
OAuth 2.0 and LibraryOAuth 2.0 and Library
OAuth 2.0 and LibraryKenji 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
 
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 2015Todi Appy Days
 
The dark side of the app
The dark side of the appThe dark side of the app
The dark side of the appSimone 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 2Jonathan LeBlanc
 
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 - BasicsSang-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) webFelix 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.pdfAppweb 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 ConnectJonathan 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
 
NextGenPSD2 OAuth SCA Mode Security Recommendations
NextGenPSD2 OAuth SCA Mode Security RecommendationsNextGenPSD2 OAuth SCA Mode Security Recommendations
NextGenPSD2 OAuth SCA Mode Security RecommendationsTorsten Lodderstedt
 

Similar a 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
 

Más de 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 TerraformMichael Peacock
 
Test driven APIs with Laravel
Test driven APIs with LaravelTest driven APIs with Laravel
Test driven APIs with LaravelMichael Peacock
 
Symfony Workflow Component - Introductory Lightning Talk
Symfony Workflow Component - Introductory Lightning TalkSymfony Workflow Component - Introductory Lightning Talk
Symfony Workflow Component - Introductory Lightning TalkMichael Peacock
 
Alexa, lets make a skill
Alexa, lets make a skillAlexa, lets make a skill
Alexa, lets make a skillMichael 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 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 talkMichael Peacock
 

Más de 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
 

Último

Cybersecurity Threats and Cybersecurity Best Practices
Cybersecurity Threats and Cybersecurity Best PracticesCybersecurity Threats and Cybersecurity Best Practices
Cybersecurity Threats and Cybersecurity Best PracticesLumiverse Solutions Pvt Ltd
 
Company Snapshot Theme for Business by Slidesgo.pptx
Company Snapshot Theme for Business by Slidesgo.pptxCompany Snapshot Theme for Business by Slidesgo.pptx
Company Snapshot Theme for Business by Slidesgo.pptxMario
 
『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书
『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书
『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书rnrncn29
 
Unidad 4 – Redes de ordenadores (en inglés).pptx
Unidad 4 – Redes de ordenadores (en inglés).pptxUnidad 4 – Redes de ordenadores (en inglés).pptx
Unidad 4 – Redes de ordenadores (en inglés).pptxmibuzondetrabajo
 
SCM Symposium PPT Format Customer loyalty is predi
SCM Symposium PPT Format Customer loyalty is prediSCM Symposium PPT Format Customer loyalty is predi
SCM Symposium PPT Format Customer loyalty is predieusebiomeyer
 
ETHICAL HACKING dddddddddddddddfnandni.pptx
ETHICAL HACKING dddddddddddddddfnandni.pptxETHICAL HACKING dddddddddddddddfnandni.pptx
ETHICAL HACKING dddddddddddddddfnandni.pptxNIMMANAGANTI RAMAKRISHNA
 
TRENDS Enabling and inhibiting dimensions.pptx
TRENDS Enabling and inhibiting dimensions.pptxTRENDS Enabling and inhibiting dimensions.pptx
TRENDS Enabling and inhibiting dimensions.pptxAndrieCagasanAkio
 
『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书
『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书
『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书rnrncn29
 
IP addressing and IPv6, presented by Paul Wilson at IETF 119
IP addressing and IPv6, presented by Paul Wilson at IETF 119IP addressing and IPv6, presented by Paul Wilson at IETF 119
IP addressing and IPv6, presented by Paul Wilson at IETF 119APNIC
 

Último (9)

Cybersecurity Threats and Cybersecurity Best Practices
Cybersecurity Threats and Cybersecurity Best PracticesCybersecurity Threats and Cybersecurity Best Practices
Cybersecurity Threats and Cybersecurity Best Practices
 
Company Snapshot Theme for Business by Slidesgo.pptx
Company Snapshot Theme for Business by Slidesgo.pptxCompany Snapshot Theme for Business by Slidesgo.pptx
Company Snapshot Theme for Business by Slidesgo.pptx
 
『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书
『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书
『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书
 
Unidad 4 – Redes de ordenadores (en inglés).pptx
Unidad 4 – Redes de ordenadores (en inglés).pptxUnidad 4 – Redes de ordenadores (en inglés).pptx
Unidad 4 – Redes de ordenadores (en inglés).pptx
 
SCM Symposium PPT Format Customer loyalty is predi
SCM Symposium PPT Format Customer loyalty is prediSCM Symposium PPT Format Customer loyalty is predi
SCM Symposium PPT Format Customer loyalty is predi
 
ETHICAL HACKING dddddddddddddddfnandni.pptx
ETHICAL HACKING dddddddddddddddfnandni.pptxETHICAL HACKING dddddddddddddddfnandni.pptx
ETHICAL HACKING dddddddddddddddfnandni.pptx
 
TRENDS Enabling and inhibiting dimensions.pptx
TRENDS Enabling and inhibiting dimensions.pptxTRENDS Enabling and inhibiting dimensions.pptx
TRENDS Enabling and inhibiting dimensions.pptx
 
『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书
『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书
『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书
 
IP addressing and IPv6, presented by Paul Wilson at IETF 119
IP addressing and IPv6, presented by Paul Wilson at IETF 119IP addressing and IPv6, presented by Paul Wilson at IETF 119
IP addressing and IPv6, presented by Paul Wilson at IETF 119
 

An introduction to Laravel Passport

Notas del editor

  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