Upgrade to Pro — share decks privately, control downloads, hide ads and more …

PassportではじめるOAuth2 #laravel_osaka

Hinaloe
October 29, 2016

PassportではじめるOAuth2 #laravel_osaka

Laravel 5.3 で公式パッケージとしてリリースされたPassport。その使い方や存在意義、特徴なんかをざっくり解説。
@Laravel.Osaka 2016 (2016.10.29.sat/MOTEX Inc.) http://php-jp.github.io/laravel-osaka-2016/

※リンクはPDFをDLしてからどうぞ

Hinaloe

October 29, 2016
Tweet

More Decks by Hinaloe

Other Decks in Technology

Transcript

  1. BVUIPSJ[BUJPO@DPEF  Ϣʔβʔ͕ಛఆΛϖʔδ PBVUIBVUIPSJ[F ʹΞΫηεͤ͞Δ ˠΫΤϦͰDMJFOU@JE SFEJSFDU@VSJ SFTQPOTF@UZQFDPEF  TDPQF

    PQUJPO TUBUF PQUJPO Λ౉͢ ˣ Ϣʔβʔ͕ϩάΠϯɺೝՄΛԡ͢ ˣ ࢦఆͨ͠ϦμΠϨΫτઌ ݩΞϓϦͷ͸ͣ ʹɺΫΤϦʹDPEFΛ ͚ͭͯϦμΠϨΫτ͞ΕΔͷͰɺ PBVUIUPLFOΛୟ͍ͯτʔΫϯΛऔಘ
  2. QFSTPOBM@BDDFTT w ݸਓ༻τʔΫϯ w ظݶ͕࣮࣭Ӭٱ ߋ৽ෆཁ  w ։ൃ༻τʔΫϯ΍ϫϯϥΠφʔ౳ʹ΋ศར w

    ΫϥΠΞϯτͷ֓೦͕ଘࡏ͠ͳ͍ಛघͳଘࡏ w ྫ͑͹-*/&/PUJGZ΋͜ΕΛ࢖ͬͯ൥Θ͍͠ೝূ ෆཁͷίʔυ͕ॻ͚ΔɺΈ͍ͨͳɻ 
  3. -FWFMτʔΫϯ؅ཧը໘ SFTPVSDFTBTTFUTKTBQQKTʹ
 Vue.component('authorized-clients', require('./ components/passport/AuthorizedClients.vue')); Vue.component('clients', require('./components/ passport/Clients.vue')); Vue.component('personal-tokens', require('./

    components/passport/PersonalAccessTokens.vue')); Λॻ͖଍ͯ͠΍Γɺ೚ҙͷWJFXͰBVUIPSJ[FEDMJFOUTDMJFOUT QFSTPOBMUPLFOTͷΑ͏ʹॻ͍ͯ΍Ε͹͓̺ ඞཁʹԠͯ͡ίϯϙʔωϯτ΋ฤू͠·͠ΐ͏ 
  4. -FWFMTUBUJDNFUIPE w 1BTTQPSUSPVUF লུͤͣʹॻ͘ͱʜʜˠ w 1BTTQPSUSPVUF GVODUJPO 3PVUF3FHJTUSBSSPVUFS \
 SPVUFSGPS"VUIPSJ[BUJPO

    
 SPVUFSGPS"DDFTT5PLFOT 
 SPVUFSGPS5SBOTJFOU5PLFOT 
 SPVUFSGPS$MJFOUT 
 SPVUFSGPS1FSTPOBM"DDFTT5PLFOT 
 ^  
  5. -FWFMTUBUJDNFUIPE w 1BTTQPSUQSVOF3FWPLFE5PLFOT SFWPLF࣌ʹ%#͔Βফ͢ w 1BTTQPSUQFSTPOBM"DDFTT$MJFOU DMJFOU*E  w 1BTTQPSUUPLFOT$BO

    BSSBZTDPQFT  w 1BTTQPSUUPLFOT&YQJSF*O %BUF5JNF*OUFSGBDFEBUFOVMM  w 1BTTQPSUSFGSFTI5PLFOT&YQJSF*O %BUF5JNF*OUFSGBDFEBUFOVMM  w 1BTTQPSUMPBE,FZT'SPN QBUI  w 1BTTQPSULFZ1BUI pMF  w 1BTTQPSUJHOPSF.JHSBUJPOT  
  6. NFNPTDPQF // kernel
 'scopes' => \Laravel\Passport\Http\Middleware\CheckScopes::class,
 'scope' => \Laravel\Passport\Http\Middleware\CheckForAnyScope::class,
 //

    router Route::get('/orders', function () {
 // ΞΫηετʔΫϯ͸"check-status"ͱ"place-orders"ɺ྆είʔϓΛ͍࣋ͬͯΔ
 })->middleware('scopes:check-status,place-orders');
 Route::get('/orders', function () {
 // ΞΫηετʔΫϯ͸ɺ"check-status"͔"place-orders"ɺͲͪΒ͔ͷείʔϓΛ͍࣋ͬͯΔ
 })->middleware('scope:check-status,place-orders');
 Route::get('/orders', function (Request $request) {
 if ($request->user()->tokenCan('place-orders')) {
 //
 }
 });
 
  7. -FWFMPWFSSJEF ͨͱ͑͹ʜʜ class BearerTokenResponse extends \League\OAuth2\Server \ResponseTypes\BearerTokenResponse
 {
 protected function

    getExtraParams(AccessTokenEntityInterface $accessToken)
 {
 return ['scope'=>$accessToken->getScopes()];
 }
 }
 
  8. 8IZ1BTTQPSU w ͜Μͳঢ়گʹ͏Ε͍͠ w ද͸41" ཪ͸"1* υϝΠϯ෼཭ ˡ࣮ࡍʹӡ༻த w ϞόΠϧΞϓϦͷόοΫΤϯυͱͯ͠

    ΋ "1*Λ࢖͏ɺ͋ Δ͍͸ͦΕΛݕ౼͍ͯ͠Δ w αʔυύʔςΟ͕ΫϥΠΞϯτΞϓϦΛ࡞ΕΔΑ͏ʹͨ͠ ͍ w 440͕ग़དྷΔΑ͏ʹ͍ͨ͠