{"id":43,"date":"2017-06-08T01:30:42","date_gmt":"2017-06-07T16:30:42","guid":{"rendered":"https:\/\/blog.capilano-fw.com\/?p=43"},"modified":"2018-02-23T04:33:59","modified_gmt":"2018-02-22T19:33:59","slug":"laravel-socialite-%e3%81%a7%e6%b0%97%e3%82%92%e3%81%a4%e3%81%91%e3%82%8b%e3%81%b9%e3%81%8d%e4%ba%8b%e3%81%ae%e3%81%be%e3%81%a8%e3%82%81","status":"publish","type":"post","link":"https:\/\/blog.capilano-fw.com\/?p=43","title":{"rendered":"Laravel \/ Socialite \u3067\u6c17\u3092\u3064\u3051\u308b\u3079\u304d\u4e8b\u306e\u307e\u3068\u3081"},"content":{"rendered":"<p>\u73fe\u5728\u306e\u958b\u767a\u3067 <a href=\"https:\/\/github.com\/laravel\/socialite\">Laravel\/Socialite <\/a> \u3092\u4f7f\u3063\u305f\u30bd\u30fc\u30b7\u30e3\u30eb\u30fb\u30ed\u30b0\u30a4\u30f3\u3092\u4f5c\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u3053\u306e\u30d1\u30c3\u30b1\u30fc\u30b8\u306f\u3068\u3066\u3082\u4fbf\u5229\u3067\u4ee5\u4e0b\u306e\u624b\u9806\u3092\u8e0f\u3080\u3060\u3051\u3067\u30e6\u30fc\u30b6\u30fc\u767b\u9332\uff0f\u30ed\u30b0\u30a4\u30f3\u306e\u624b\u9593\u3092\u7701\u304f\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<p>\uff11\uff0eTwitter \u3084 Facebook \u306e\u7279\u5b9a\u30da\u30fc\u30b8\u30d8\u30ea\u30f3\u30af\u3092\u8cbc\u308b<br \/>\n\uff12\uff0e\u30a2\u30af\u30bb\u30b9\u8a31\u53ef\u306e\u8a2d\u5b9a\uff08\u3059\u3067\u306b\u8a31\u53ef\u8a2d\u5b9a\u3055\u308c\u3066\u3044\u308c\u3070\u3053\u3053\u306f\u30b9\u30ad\u30c3\u30d7\uff09<br \/>\n\uff13\uff0e\u6307\u5b9a\u3057\u305f\u30da\u30fc\u30b8\u30d8\u30ea\u30c0\u30a4\u30ec\u30af\u30c8\u3057\u3066\u304f\u308b\u306e\u3067\u3001\u305d\u3053\u3067\u30e6\u30fc\u30b6\u30fc\u60c5\u5831\u3092\u767b\u9332 or \u81ea\u52d5\u30ed\u30b0\u30a4\u30f3<\/p>\n<p>\u3072\u3068\u3064\u3072\u3068\u3064\u30bd\u30fc\u30b7\u30e3\u30eb\u30ed\u30b0\u30a4\u30f3\u3092\u5b9f\u88c5\u3057\u3066\u3044\u305f\u4e00\u6614\u306e\u3053\u3068\u3092\u8003\u3048\u308b\u3068\u3069\u308c\u3060\u3051\u958b\u767a\u304c\u7701\u7565\u3055\u308c\u305f\u3053\u3068\u304b\u3068\u30db\u30f3\u30c8\u306b\u611f\u5fc3\u3057\u307e\u3059\u306d\u3002<\/p>\n<p>\u3055\u3066\u3001\u3053\u3093\u306a\u4fbf\u5229\u306a Laravel\/Socialite \u3067\u3059\u304c\u3001\u30e6\u30fc\u30b6\u30fc\u767b\u9332\u3001\u3082\u3057\u304f\u306f\u30ed\u30b0\u30a4\u30f3\u3059\u308b\u969b\u306b\u3044\u304f\u3064\u304b\u6c17\u3092\u3064\u3051\u3066\u304a\u304b\u306a\u3051\u308c\u3070\u306a\u3089\u306a\u3044\u3053\u3068\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<p>\u4eca\u56de\u306f\u305d\u308c\u3089\u3092\u81ea\u5206\u3078\u306e\u5099\u5fd8\u9332\u3068\u3057\u3066\u3082\u8a18\u4e8b\u306b\u3057\u3066\u304a\u5c4a\u3051\u3057\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<p><strong>\u6c17\u3092\u3064\u3051\u308b\u3079\u304d\u3053\u3068<\/strong><\/p>\n<p>\uff11\uff0e\u30e6\u30fc\u30b6\u30fc\u30c6\u30fc\u30d6\u30eb<\/p>\n<p>\u30c7\u30d5\u30a9\u30eb\u30c8\u3067 Laravel \u306e\u30ed\u30b0\u30a4\u30f3\u60c5\u5831\u306f\u30e1\u30fc\u30eb\u30a2\u30c9\u30ec\u30b9\u3068\u30d1\u30b9\u30ef\u30fc\u30c9\u3068\u306a\u3063\u3066\u3044\u307e\u3059\u3002<br \/>\n\u305d\u306e\u305f\u3081\u3001\u30e6\u30fc\u30b6\u30fc\u767b\u9332\u3092\u3057\u3088\u3046\u3068\u3059\u308b\u306a\u3089\u5358\u7d14\u306b\u30d5\u30a7\u30a4\u30b9\u30d6\u30c3\u30af\u306a\u3069\u304b\u3089\u63d0\u4f9b\u3055\u308c\u308b\u30e1\u30fc\u30eb\u30a2\u30c9\u30ec\u30b9\u3068\u30e9\u30f3\u30c0\u30e0\u306a\u30d1\u30b9\u30ef\u30fc\u30c9\u3092\u4f7f\u3063\u3066\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u3057\u3088\u3046\u3068\u3059\u308b\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<pre>\\App\\User::create([\r\n    'email' =&gt; $socialite_user-&gt;email,\r\n    'password' =&gt; str_random()\r\n]);<\/pre>\n<p>\u3057\u304b\u3057\u3001\u3053\u308c\u3067\u306f\u4eca\u5f8c\u30bd\u30fc\u30b7\u30e3\u30eb\u30ed\u30b0\u30a4\u30f3\u306e\u30e1\u30fc\u30eb\u30a2\u30c9\u30ec\u30b9\u3092\u5909\u66f4\u3055\u308c\u3066\u3057\u307e\u3063\u305f\u5834\u5408\u306b\u9055\u3046\u30e1\u30fc\u30eb\u30a2\u30c9\u30ec\u30b9\u304c\u63d0\u4f9b\u3055\u308c\u308b\u3053\u3068\u306b\u306a\u308b\u305f\u3081\u540c\u4e00\u306e\u30e6\u30fc\u30b6\u30fc\u3067\u3042\u3063\u3066\u3082\u30e1\u30fc\u30eb\u30a2\u30c9\u30ec\u30b9\u5909\u66f4\u5f8c\u306f\u518d\u5ea6\u65b0\u3057\u3044\u30e6\u30fc\u30b6\u30fc\u3068\u3057\u3066\u8a8d\u8b58\u3055\u308c\u308b\u3053\u3068\u306b\u306a\u3063\u3066\u3057\u307e\u3044\u307e\u3059\u3002<\/p>\n<p>\u3053\u308c\u3092\u9632\u6b62\u3059\u308b\u305f\u3081\u306b\u306f\u30e6\u30fc\u30b6\u30fc\u30c6\u30fc\u30d6\u30eb\uff08\u3082\u3057\u304f\u306f\u30bd\u30fc\u30b7\u30e3\u30eb\u30ed\u30b0\u30a4\u30f3\u5c02\u7528\u30c6\u30fc\u30d6\u30eb\uff09\u306b\u30ed\u30b0\u30a4\u30f3\u306b\u4f7f\u7528\u3059\u308b\u30b5\u30a4\u30c8\u3068\u30e6\u30cb\u30fc\u30afID\u3092\u4fdd\u5b58\u3057\u3001\u30ed\u30b0\u30a4\u30f3\u3059\u308b\u969b\u306b\u306f\u3053\u308c\u3089\u3067\u8a8d\u8a3c\u3092\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<p>\u305d\u3053\u3067 migration \u306b provider_name \u3068 provider_id \u306a\u3069\u306e\u3088\u3046\u306a\u30ab\u30e9\u30e0\u3092\u8ffd\u52a0\u3057\u307e\u3059\u3002<\/p>\n<pre>\/**\r\n* Run the migrations.\r\n*\r\n* @return void\r\n*\/\r\npublic function up()\r\n{\r\n    Schema::create('users', function (Blueprint $table) {\r\n        $table-&gt;increments('id');\r\n        $table-&gt;string('name');\r\n        $table-&gt;string('email')-&gt;unique();\r\n        $table-&gt;string('password');\r\n        $table-&gt;string('provider_name')-&gt;nullable();  \/\/ \u2190\u3053\u3053\u3002facebook \u3084 twitter \u306a\u3069\u304c\u5165\u308b\r\n        $table-&gt;string('provider_id')-&gt;nullable();  \/\/ \u2190\u3053\u3053\u3002\u5404\u30b5\u30a4\u30c8\u306e\u30e6\u30fc\u30b6\u30fcID\r\n        $table-&gt;rememberToken();\r\n        $table-&gt;timestamps();\r\n    });\r\n}<\/pre>\n<p>\u203b\u901a\u5e38\u306e\u30e6\u30fc\u30b6\u30fc\u767b\u9332\u306e\u969b\u306f provider_name, provider_id \u306f\u5fc5\u8981\u306a\u3044\u306e\u3067 nullbale() \u3092\u4ed8\u3051\u52a0\u3048\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u305d\u3057\u3066\u3001\u30ed\u30b0\u30a4\u30f3\u306f\u3053\u308c\u3089\uff12\u3064\u306e\u30ab\u30e9\u30e0\u3092\u5229\u7528\u3057\u3066\u30c1\u30a7\u30c3\u30af\u3092\u884c\u3044\u307e\u3059\u3002<br \/>\n\uff08\u203b\u305f\u3060\u3057\u3001\u3053\u308c\u3067\u306f\u307e\u3060\u672a\u5b8c\u6210\u3067\u3059\u3002\u6b21\u306e\u9805\u76ee\u3082\u30c1\u30a7\u30c3\u30af\u3057\u3066\u304f\u3060\u3055\u3044\uff09<\/p>\n<pre>$user = \\App\\User::where('provider_name', $driver)\r\n    -&gt;where('provider_id', $socialite_user-&gt;id)\r\n    -&gt;first();<\/pre>\n<p>\uff12\uff0eprovider_name \u3068 provider_id \u306e\uff12\u3064\u3060\u3051\u3067\u30e6\u30fc\u30b6\u30fc\u30c1\u30a7\u30c3\u30af\u3092\u3059\u308b\u3068\u30a8\u30e9\u30fc\u304c\u767a\u751f<\/p>\n<p>\u5148\u307b\u3069\u8ffd\u52a0\u3057\u305f\uff12\u3064\u306e\u30ab\u30e9\u30e0\u3067\u306e\u30c1\u30a7\u30c3\u30af\u3060\u3051\u3067\u30e6\u30fc\u30b6\u30fc\u767b\u9332\u3092\u5b9f\u884c\u3059\u308b\u3068\u30a8\u30e9\u30fc\u304c\u767a\u751f\u3059\u308b\u5834\u5408\u304c\u3042\u308a\u307e\u3059\u3002<br \/>\n\u4f8b\u3048\u3070\u4ee5\u4e0b\u306e\u4f8b\u3092\u8003\u3048\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<p>\uff11\uff0e\u30e6\u30fc\u30b6\u767b\u9332\u306f\u30d5\u30a7\u30a4\u30b9\u30d6\u30c3\u30af\u3092\u4f7f\u3063\u305f\u3002<br \/>\n\uff12\uff0e\u305d\u306e\u5f8c\u3001\u30c4\u30a4\u30c3\u30bf\u30fc\u3082\u9762\u767d\u305d\u3046\u306a\u306e\u3067\u767b\u9332\u3057\u305f\u3002<br \/>\n\uff13\uff0e\u30d5\u30a7\u30a4\u30b9\u30d6\u30c3\u30af\u3067\u767b\u9332\u3057\u305f\u306e\u3092\u5fd8\u308c\u3066\u30c4\u30a4\u30c3\u30bf\u30fc\u306e\u30bd\u30fc\u30b7\u30e3\u30eb\u30ed\u30b0\u30a4\u30f3\u3067\u8a8d\u8a3c\u3092\u5b9f\u884c\u3057\u305f\uff08\u2190\u30a8\u30e9\u30fc\u304c\u51fa\u307e\u3059\uff09<\/p>\n<p>\u306a\u305c\u306a\u3089\u3001\u3059\u3067\u306b\u767b\u9332\u3055\u308c\u3066\u3044\u308b provider_name \u3068 provier_id \u306f\u30d5\u30a7\u30a4\u30b9\u30d6\u30c3\u30af\u306e\u3082\u306e\u306a\u306e\u3067\u3001\u5148\u307b\u3069\u306e where \u53e5\u3092\u4f7f\u3063\u305f\u30e6\u30fc\u30b6\u30fc\u30c1\u30a7\u30c3\u30af\u3067\u306f\u300c\u8a72\u5f53\u306a\u3057\u300d\u3068\u306a\u3063\u3066\u3057\u307e\u3044\u307e\u3059\u3002<\/p>\n<p>\u8a72\u5f53\u306a\u3057\u3068\u306a\u308b\u3068\u3001\u30d7\u30ed\u30b0\u30e9\u30e0\u306e\u65b9\u3067\u306f\u30e6\u30fc\u30b6\u30fc\u767b\u9332\u3092\u3059\u308b\u306f\u305a\u3067\u3059\u3002<br \/>\n\u3057\u304b\u3057\u305d\u3046\u306a\u3063\u305f\u5834\u5408\u3001\u3082\u3057\u3053\u306e\u30e6\u30fc\u30b6\u30fc\u306e\u30d5\u30a7\u30a4\u30b9\u30d6\u30c3\u30af\u3068\u30c4\u30a4\u30c3\u30bf\u30fc\u306e\u30e1\u30fc\u30eb\u30a2\u30c9\u30ec\u30b9\u304c\u540c\u3058\u3060\u3063\u305f\u5834\u5408\u306f\u3069\u3046\u306a\u308b\u3067\u3057\u3087\u3046\u3002<\/p>\n<p>\u305d\u3046\u3067\u3059\u3002<br \/>\nmigration \u306b\u306f email \u306f\u30e6\u30cb\u30fc\u30af\u8a2d\u5b9a\u304c\u3055\u308c\u3066\u3044\u307e\u3059\u306e\u3067\u30a8\u30e9\u30fc\u304c\u767a\u751f\u3057\u3066\u3057\u307e\u3046\u308f\u3051\u3067\u3059\u3002<br \/>\n\u3064\u307e\u308a\u3001\u300c\u3082\u3046\u3059\u3067\u306b\u305d\u306e\u30e1\u30fc\u30eb\u30a2\u30c9\u30ec\u30b9\u306f\u767b\u9332\u3055\u308c\u3066\u308b\u3088\uff01\u300d\u30a8\u30e9\u30fc\u3067\u3059\u306d\u3002<\/p>\n<p>\u305d\u3053\u3067\u3053\u308c\u3092\u56de\u907f\u3059\u308b\u305f\u3081\u306b\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u30e1\u30fc\u30eb\u30a2\u30c9\u30ec\u30b9\u3067\u306e\u30c1\u30a7\u30c3\u30af\u3082 orWhere \u3067\u8ffd\u52a0\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<pre>$user = \\App\\User::where(function($query) use($socialite_user, $driver){\r\n\r\n    $query-&gt;where('provider_name', $driver)\r\n    -&gt;where('provider_id', $socialite_user-&gt;id);\r\n\r\n})\r\n-&gt;orWhere('email', $socialite_user-&gt;email)\r\n-&gt;first();<\/pre>\n<p>\u3053\u308c\u3067\u4ed6\u306e\u30bd\u30fc\u30b7\u30e3\u30eb\u30ed\u30b0\u30a4\u30f3\u3092\u8a66\u3055\u308c\u3066\u3082\u554f\u984c\u306a\u3044\u3067\u3057\u3087\u3046\u3002<\/p>\n<p>\uff13\uff0e\u30c4\u30a4\u30c3\u30bf\u30fc\u306e\u30bd\u30fc\u30b7\u30e3\u30eb\u30ed\u30b0\u30a4\u30f3\u306f\u30e1\u30fc\u30eb\u30a2\u30c9\u30ec\u30b9\u3092\u30c7\u30d5\u30a9\u30eb\u30c8\u3067\u63d0\u4f9b\u3057\u306a\u3044<\/p>\n<p>\u3053\u308c\u306f\u5c11\u3057\u9762\u5012\u306a\u306e\u3067\u3059\u304c\u3001\u30c4\u30a4\u30c3\u30bf\u30fc\u306e\u30bd\u30fc\u30b7\u30e3\u30eb\u30ed\u30b0\u30a4\u30f3\u3067\u30e1\u30fc\u30eb\u30a2\u30c9\u30ec\u30b9\u3092\u53d6\u5f97\u3057\u305f\u3044\u5834\u5408\u306f\u4ee5\u4e0b\u306e\uff12\u3064\u306e\u60c5\u5831\u3092\u8ffd\u52a0\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<p>\uff11\uff0e\u30d7\u30e9\u30a4\u30d0\u30b7\u30fc\u30dd\u30ea\u30b7\u30fc\u306eURL<br \/>\n\uff12\uff0e\u5229\u7528\u898f\u7d04\u306eURL<\/p>\n<p>\u3082\u3057\u30e1\u30fc\u30eb\u30a2\u30c9\u30ec\u30b9\u3092\u53d6\u5f97\u3057\u305f\u3044\u306e\u306a\u3089\u3053\u308c\u3089\u3092 Application Management \u306e settings \u30bf\u30d6\u3067\u767b\u9332\u3057\u3001\u3055\u3089\u306b permissions \u30bf\u30d6\u306e\u300cAdditional Permissions\u300d\u3067 \u300cRequest email addresses from users\u300d\u306b\u30c1\u30a7\u30c3\u30af\u3092\u5165\u308c\u3066\u4fdd\u5b58\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n<p>\u4ee5\u4e0a\u3001Socialte \u306e\u6ce8\u610f\u3059\u3079\u304d\u70b9\u306e\u307e\u3068\u3081\u3067\u3057\u305f\u3002<br \/>\n\u3067\u304d\u308c\u3070\u4eca\u5f8c\u306f Socialite \u306e\u65b9\u3067\u30e6\u30fc\u30b6\u30fc\u767b\u9332 or \u81ea\u52d5\u30ed\u30b0\u30a4\u30f3\u3092\u81ea\u52d5\u7684\u306b\u884c\u3063\u3066\u304f\u308c\u308b\u30e1\u30bd\u30c3\u30c9\u306a\u3069\u3092\u8ffd\u52a0\u3057\u3066\u304f\u308c\u308b\u3068\u5b09\u3057\u3044\u306a\u3068\u601d\u3044\u3064\u3064\u4eca\u56de\u306e\u8a18\u4e8b\u3092\u7d42\u4e86\u3057\u307e\u3059<\/p>\n<p>\uff08\u3082\u3057\u304b\u3057\u3066\u3082\u3046\u3001\u3042\u308b\uff1f\uff1f\uff1f\uff09<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u73fe\u5728\u306e\u958b\u767a\u3067 Laravel\/Socialite \u3092\u4f7f\u3063\u305f\u30bd\u30fc\u30b7\u30e3\u30eb\u30fb\u30ed\u30b0\u30a4\u30f3\u3092\u4f5c\u3063\u3066\u3044\u307e\u3059\u3002 \u3053\u306e\u30d1\u30c3\u30b1\u30fc\u30b8\u306f\u3068\u3066\u3082\u4fbf\u5229\u3067\u4ee5\u4e0b\u306e\u624b\u9806\u3092\u8e0f\u3080\u3060\u3051\u3067\u30e6\u30fc\u30b6\u30fc\u767b\u9332\uff0f &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/blog.capilano-fw.com\/?p=43\" class=\"more-link\"><span class=\"screen-reader-text\">&#8220;Laravel \/ Socialite \u3067\u6c17\u3092\u3064\u3051\u308b\u3079\u304d\u4e8b\u306e\u307e\u3068\u3081&#8221; \u306e<\/span>\u7d9a\u304d\u3092\u8aad\u3080<\/a><\/p>\n","protected":false},"author":1,"featured_media":56,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[7],"class_list":["post-43","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-laravel","tag-7"],"_links":{"self":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts\/43","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=43"}],"version-history":[{"count":12,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts\/43\/revisions"}],"predecessor-version":[{"id":332,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts\/43\/revisions\/332"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/media\/56"}],"wp:attachment":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=43"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=43"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=43"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}