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

Laravel + Auth0で複数のSNS認証を簡単に実現.pdf

02886e95c50822b9aa2552da1e518491?s=47 Takayuki
August 07, 2019

Laravel + Auth0で複数のSNS認証を簡単に実現.pdf

Laravel + Auth0で複数のSNS認証を簡単に実現

02886e95c50822b9aa2552da1e518491?s=128

Takayuki

August 07, 2019
Tweet

More Decks by Takayuki

Other Decks in Programming

Transcript

  1. Laravel + Auth0Ͱෳ਺ͷ SNSೝূΛ؆୯ʹ࣮ݱ Laravel + Auth0Ͱෳ਺ͷ SNSೝূΛ؆୯ʹ࣮ݱ

  2. 3 LaravelͰͷ࣮૷ํ๏ Agenda 2 Auth0ͱ͸ 1 ࣗݾ঺հ 4 Demo

  3. 1 ࣗݾ঺հ

  4. 4 ࣗݾ঺հ ◆໊લ ླ໦ ޹೭(Suzuki Takayuki) ◆ࣗݾ঺հ ɾ1990೥ɺਆಸ઒ݝੜ·Εɻ ɾࣾձਓʹͳ͔ͬͯΒɺϓϩάϥϛϯάΛ࢝ΊΔɻ ɾ2015೥ʹϑϧεϐʔυʹೖࣾ͠ɺ2017೥ʹϑϦʔϥ

    ϯεΛ΍ͬͨޙʹ2017೥11݄ʹԭೄͰىۀɻ ◆झຯ ίεϓϨɺԻָϥΠϒɺϚϥιϯେձʹग़Δɺ໺ٿ؍ ઓ ◆Twitter @kanbo0605
  5. 5 ࣗݾ঺հ 7/13ʹLaravel ΧϯϑΝϨϯε ୆࿷Ͱ΋ొஃ͖ͯ͠·ͨ͠ʂ ৄ͘͠͸ͪ͜Β
 https://dev.re-build.company/ entry/2019/07/23/193108

  6. Copyright Re:Build.inc All Rights Reserved. 1.ձࣾ঺հ ◆ձ໊ࣾ גࣜձࣾRe:Build ◆ॅॴ ԭೄݝԭೄࢢதԝ̍ஸ໨̍̒−̕

    ◆ࣄۀ಺༰ ɾࣗࣾWEBαʔϏεͷاըɾ։ൃɻ ɾडୗ։ൃ ◆ࣾһ 6໊ ◆ΤϯδχΞͷಇ͖ํ ϦϞʔτϫʔΫՄೳͳࣗ༝ͳಇ͖ํΛਪ঑ͯ͠·͢ʂ
  7. 2 Auth0ͱ͸

  8. 8 ͜ͷࢿྉʹ͍ͭͯ https://speakerdeck.com/bumptakayuki/laravel-plus-auth0-plus-stripe-deecsaitowozuo-tutemita Ҏલɺൃදͨ͠಺༰ʹ ෇͚Ճ͑ͨ΋ͷͰ͢ʂ

  9. 9 ର৅ऀ ɾAuth0ͷಋೖΛݕ౼͍ͯ͠Δํ ɾೝূج൫ͷ࣮૷ʹ೰ΜͰ͍Δํ ɾLaravelͰAuth0Λ࣮૷ͯ͠Έ͍ͨํ

  10. 1 0 Auth0ͱ͸ ɾ֓ཁ Auth0͸WebΞϓϦ΍ϞόΠϧɺAPIͳͲ ʹରͯ͠ೝূɾೝՄͷαʔϏεΛΫϥ΢υ Ͱఏڙ͍ͯ͠Δɺ͍ΘΏΔIDaaS (Identity as a

    Service)ϕϯμʔͰ͢ɻ ɾΦεεϝͷํ اۀ͕΋ͭWebΞϓϦέʔγϣϯ΍API, Native Mobile AppͳͲͰϢʔβʔೝূ΍ ೝՄɺηΩϡϦςΟΛ૊ΈࠐΈ͍͚ͨΕ Ͳ΋࣮૷͕೉͍͠ɻ https://qiita.com/furuth/items/8826b66a3ec2b2b14222
  11. 11 ֤ݴޠ͝ͱͰνϡʔ τϦΞϧ͕ॆ࣮ͯ͠ ͓Γɺ؆୯ʹಋೖͰ ͖·͢ɻ ओཁͳSNSͱ΄ͱΜͲ࿈ ܞ͓ͯ͠Γɺ࿈ܞํ๏΋ ؆୯ͰศརͰ͢ɻ μογϡϘʔυͰͲͷSNS͔ ΒϩάΠϯ͕͋Δ͔֬ೝͰ͖

    Δ ؆୯ʹಋೖͰ͖Δ ϢʔβೝূΛҰݩ؅ཧͰ ͖Δ ϝϦοτɾಛ௃ ๛෋ͳ࿈ܞઌ 2 ʙϝϦοτʙ 1 3
  12. 1 2 ๛෋ͳ࿈ܞઌ Auth0ͱ͸

  13. 1 3 ϢʔβΛҰݩ؅ཧ Auth0ͱ͸

  14. 1 4 ෳ਺ͷσόΠεʹରԠ Auth0ͱ͸

  15. 1 5 ྉۚମܥ https://auth0.com/pricing

  16. 3 LaravelͰͷ࣮૷ํ๏

  17. ΞϓϦέʔγϣϯ ϩάΠϯ͔Βܾࡁ·ͰͷྲྀΕ /index TOPϖʔδ΁ ঎඼ৄࡉϖʔδભҠ ࣌ʹϩάΠϯ ϩάΠϯ੒ޭͨ͠Β ηογϣϯ͸Laravelଆ Ͱ؅ཧ ೝূ

    ܾࡁ ঎඼ߪೖ͔Βܾࡁը໘΁
  18. 1 8 ެࣜͷAuth0ͷLaravelνϡʔτϦΞϧ https://auth0.com/docs/quickstart/webapp/laravel/01-login

  19. 1 9 खॱ ᶃAuth0ͷ؅ཧը໘ͰΞϓϦέʔγϣϯͷઃఆΛߦ͏ɻ ᶄLaravelΛΠϯετʔϧ ᶅcomposer require auth0/login:”~5.0" Λ࣮ߦ ᶆLoginServiceProviderΛઃఆ

    ᶇphp artisan vendor:publishΛ࣮ߦ ᶈ.envΛฤू ᶉroutes/api.phpΛฤू ᶊίϯτϩʔϥΛ࡞੒ ᶋconfig/auth.phpΛฤू ᶌbladeϑΝΠϧΛฤू
  20. 2 0 ᶃAuth0ͷ؅ཧը໘ͰΞϓϦέʔγϣϯͷઃఆΛߦ͏ɻ

  21. 2 1 ᶄLaravelΛΠϯετʔϧ https://readouble.com/laravel/5.5/ja/installation.html

  22. 2 2 ᶅcomposer require auth0/login:”~5.0" Λ࣮ߦ Auth0ϓϥάΠϯΛΠϯετʔϧ Πϯετʔϧ͕׬ྃ͢Δͱɺ2ͭͷϓϥάΠϯ͕௥Ճ͞ΕΔɻ vendor\auth0\auth0-php vendor\auth0\login

  23. 2 3 ᶆLoginServiceProviderΛઃఆ config/app.phpΛฤू ԼهΛ௥Ճ

  24. 2 4 ᶆLoginServiceProviderΛઃఆ AppServiceProvider .phpΛฤू ԼهΛ௥Ճ

  25. 2 5 ᶇphp artisan vendor:publishΛ࣮ߦ ׬ྃ͢Δͱɺconfig/laravel-auth0.php͕࡞੒͞Εɺ σϑΥϧτͷઃఆϑΝΠϧ͕ެ։͞Ε·ͨ͠ɻ

  26. 2 6 ᶈ.envΛฤू ઌ΄Ͳ࡞੒ͨ͠ΞϓϦέʔγϣϯʹهࡌ͞Ε͍ͯΔυϝΠϯ,ID,ύε ϫʔυΛLaravelΞϓϦέʔγϣϯͷ.envʹ௥Ճ͠·͢ɻ

  27. 2 7 ᶉroutes/api.phpΛฤू

  28. 2 8 ᶊίϯτϩʔϥΛ࡞੒

  29. 2 9 ᶋconfig/auth.phpΛฤू ೝূํ๏ΛAuth0ʹมߋ

  30. 3 0 ᶌbladeϑΝΠϧΛฤू

  31. 3 1 Auth0ͷRuleͱ͸ʁ ϧʔϧ͸ɺϢʔβʔ͕ΞϓϦέʔγϣϯΛೝূ͢ Δͱ͖ʹ࣮ߦ͞ΕΔJavaScriptؔ਺Ͱ͢ɻ ͜ΕΒ͸ɺೝূϓϩηε͕׬ྃ͢Δͱ࣮ߦ͞Εɺ Auth0ͷػೳΛΧελϚΠζ͓Αͼ֦ு͢ΔͨΊ ʹ࢖༻Ͱ͖·͢ɻ ηΩϡϦςΟ্ͷཧ༝͔Βɺϧʔϧίʔυ͸ɺα ϯυϘοΫε಺ͷଞͷAuth0ςφϯτͷίʔυ͔

    Β෼཭࣮ͯ͠ߦ͞Ε·͢ɻ https://auth0.com/docs/rules
  32. 3 2 Auth0ͷRuleͷྫ ɾෳࡶͳϩδοΫʢJavaScriptͰهड़Ͱ͖Δ΋ͷʣʹج͍ͮͯঝೝϧʔϧΛ࡞ ੒ ɾϗϫΠτϦετΛ࡞੒Ͱ͖ɺిࢠϝʔϧͷ಺༰ʹج͍ͮͯΞΫηεΛڋ൱ ɾϩάΠϯ͕ϦΞϧλΠϜͰൃੜͨ͠৔߹ɺAPIΛհͯ͠ଞͷγεςϜ(Slack ͳͲ)ʹ௨஌ ͳͲ https://auth0.com/docs/rules

  33. 3 3 Ruleͷ௥Ճ RuleΛ৽ن࡞੒

  34. 3 4 Ruleͷ௥Ճ ෳ਺ͷύλʔϯͷRule͕ ࣄલʹ༻ҙ͞Ε͍ͯΔ

  35. 3 5 Ruleͷ௥Ճ RuleͰ࢖༻͢Δ؀ڥม਺ ΋ઃఆͰ͖Δ

  36. 3 6 Ruleͷྫ MFA(ೋஈ֊ೝূ)ͷઃఆ ΋؆୯ʹͰ͖Δʂ

  37. 3 7 Ruleͷྫ Ϣʔβʔ͕αΠϯΞοϓ͢Δ ͨͼʹεϥοΫνϟωϧʹϝο ηʔδΛૹ৴͠·͢ɻ

  38. 3 8 Ruleͷྫ ϝʔϧΞυϨεͷυϝΠϯʹ ΑΔ੍ݶ

  39. 3 9 Ruleͷྫ Ϣʔβ৘ใ΋ΦϒδΣΫτ͔ Βࡉ͔͘औಘͰ͖Δ https://auth0.com/docs/rules/references/user-object

  40. WWW.SITE2MAX.PRO Free PowerPoint & KeyNote Templates 4 DEMO EC Site

    EC Site https://murmuring-tor-53965.herokuapp.com/
  41. 4 1 ࣮ࡍʹಈ͔͢

  42. 4 2 ࣮ࡍʹಈ͔͢ ࠓճ͸GoogleɺFacebookɺ TwitterɺGithubʹରԠ

  43. 4 3 ࣮ࡍʹಈ͔͢

  44. 4 4 ࣮ࡍʹಈ͔͢ MFA(ೋஈ֊ೝূ)ͷը໘

  45. 4 5 ࣮ࡍʹಈ͔͢

  46. 4 6 ࣮ࡍʹಈ͔͢

  47. 4 7 ࣮૷ͯ͠Έͨײ૝(ओ؍) ɾ࣮૷͕͘͢͝؆୯ʹͰ͖ͨ(2೔͘Β͍ͰECαΠτ͕׬੒) ɾҰ౓ɺ࣮૷ͯ͠͠·͑͹ɺSNSͷ࿈ܞઌ૿΍͢ͷ͸ϘλϯΛ ϙνϙν͢Δ͚ͩͰOKʂ ɾηΩϡϦςΟͷ୲อ͸Auth0ଆ͕୲อͯ͘͠ΕΔ ɾΞΫςΟϒϢʔβ਺ʹΑͬͯ՝ۚ͞ΕΔͷͰɺ࠷ॳ͸௿ίε τͰ཈͑ͯٸ֦େ͢ΔΑ͏ͳελʔτΞοϓاۀͩͱ޲͍͍ͯ Δ͔΋͠Εͳ͍ɻ

  48. 4 8 ࢀߟ https://qiita.com/furuth/items/8826b66a3ec2b2b14222 https://dev.classmethod.jp/cloud/auth0-overview/ https://www.hypertextcandy.com/laravel-tried-auth0

  49. 4 9 ࠂ஌ 10/12 PHPΧϯϑΝϨϯεԭೄ։࠵͠·͢ʂ https://phpcon.okinawa.jp