{"id":3002,"date":"2018-06-06T15:07:49","date_gmt":"2018-06-06T06:07:49","guid":{"rendered":"http:\/\/taitan916.info\/blog\/?p=3002"},"modified":"2024-02-20T18:48:38","modified_gmt":"2024-02-20T09:48:38","slug":"post-3002","status":"publish","type":"post","link":"https:\/\/taitan916.info\/blog\/archives\/3002","title":{"rendered":"PHP\u3067\u30bd\u30fc\u30b7\u30e3\u30eb(SNS)\u30ed\u30b0\u30a4\u30f3\u3059\u308b\u65b9\u6cd52018"},"content":{"rendered":"<p>\u4e45\u3057\u3076\u308a\u306b\u30bd\u30fc\u30b7\u30e3\u30eb(SNS)\u30ed\u30b0\u30a4\u30f3\u3092\u5b9f\u88c5\u3059\u308b\u6a5f\u4f1a\u304c\u3042\u3063\u305f\u3002\u4ee5\u524d\u306b<a href=\"http:\/\/taitan916.info\/blog\/?p=2720\" target=\"_blank\" rel=\"noopener\">\u5bfe\u5fdc\u65b9\u6cd5\u3092\u66f8\u3044\u3066\u304a\u3044\u305f<\/a>\u306e\u3067\u305d\u306e\u307e\u307e\u3044\u3051\u308b\u304b\u3068\u601d\u3063\u305f\u304c\u3001\u6240\u3005\u8e93\u3044\u305f\u306e\u30672018\u5e74\u7248\u3068\u3057\u3066\u65b0\u305f\u306b\u30e1\u30e2\u3002\u5c1a\u3001\u4f7f\u7528\u3059\u308bSNS\u306fFacebook \/ Twitter \/\u00a0 Google\u3068\u3059\u308b\u3002<\/p>\n<p>&nbsp;<\/p>\n<h2>opauth\u3092\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9<\/h2>\n<p>\u4ee5\u4e0b\u3088\u308a\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3059\u308b\u3002<\/p>\n<p><a href=\"https:\/\/github.com\/opauth\/opauth\" target=\"_blank\" rel=\"noopener\">https:\/\/github.com\/opauth\/opauth<\/a><\/p>\n<p>\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u3068URL\u306f\u4ee5\u4e0b\u3068\u60f3\u5b9a\u3059\u308b\u3002<\/p>\n<p><strong>\/\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\u30eb\u30fc\u30c8\/user\/login<\/strong><\/p>\n<p><strong>http:\/\/test.com\/user\/login<\/strong><\/p>\n<p>&nbsp;<\/p>\n<h2>\u30d5\u30a1\u30a4\u30eb\u306e\u8a2d\u7f6e<\/h2>\n<p>example\u5185\u306e\u30d5\u30a1\u30a4\u30eb\u3068lib\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u3092login\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306b\u8a2d\u7f6e\u3059\u308b\u3002<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">login\/\r\n\u3000\u251c.htaccess\r\n\u3000\u251ccallback.php\r\n\u3000\u251cindex.php\r\n\u3000\u2514lib\/<\/pre>\n<p>\/lib\/Opauth\/Strategy\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u5185\u306b\u5229\u7528\u3057\u305f\u3044SNS\u306e\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u3092\u4f5c\u6210\u3059\u308b\u3002<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">Strategy\/\r\n\u3000\u251cFacebook\r\n\u3000\u251cTwitter\r\n\u3000\u2514Google<\/pre>\n<p>\u5404\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306b\u306f\u4ee5\u4e0b\u30da\u30fc\u30b8\u304b\u3089zip\u30d5\u30a1\u30a4\u30eb\u3092\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3057\u305f\u3082\u306e\u3092\u89e3\u51cd\u3057\u3066\u30a2\u30c3\u30d7\u3059\u308b\u3002<\/p>\n<p><a href=\"http:\/\/www.opauth.org\/\" target=\"_blank\" rel=\"noopener\">http:\/\/www.opauth.org\/<\/a><\/p>\n<p>&nbsp;<\/p>\n<h2>\u30d5\u30a1\u30a4\u30eb\u306e\u7de8\u96c6\u3068\u8a2d\u5b9a<\/h2>\n<p>login\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306eopauth.conf.php\u3092\u7de8\u96c6\u3059\u308b\u3002<\/p>\n<ul>\n<li>security_salt\u306f\u9069\u5f53\u306a\u82f1\u6570\u5b57<\/li>\n<li>Strategy\u306f\u5229\u7528\u3057\u305f\u3044SNS\u306eAppKey\u7b49<\/li>\n<li>path\u306f\u4eca\u56de\u3060\u3068'path' =&gt; '\/user\/login\/',<\/li>\n<\/ul>\n<p>login\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306eindex.php\u3092\u7de8\u96c6\u3059\u308b\u3002<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">define('OPAUTH_LIB_DIR', dirname(dirname(__FILE__)).'\/lib\/Opauth\/');\r\n\u2193\u2193\r\ndefine('OPAUTH_LIB_DIR', dirname(__FILE__).'\/lib\/Opauth\/');<\/pre>\n<p>login\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306ecallback.php\u3092\u7de8\u96c6\u3059\u308b\u3002<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">define('OPAUTH_LIB_DIR', dirname(dirname(__FILE__)).'\/lib\/Opauth\/');\r\n\u2193\u2193\r\ndefine('OPAUTH_LIB_DIR', dirname(__FILE__).'\/lib\/Opauth\/');<\/pre>\n<p>Notice\u30a8\u30e9\u30fc\u304c\u51fa\u305f\u304c\u539f\u56e0\u304c\u5206\u304b\u3089\u306a\u3044\u306e\u3067\/lib\/Opauth\/Opauth.php\u306e124\u884c\u76ee\u3092\u30b3\u30e1\u30f3\u30c8\u30a2\u30a6\u30c8\u3002<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">trigger_error('No strategy is requested. Try going to '.$this-&gt;env['complete_path'].$sampleStrategy['strategy_url_name'].' to authenticate with '.$sampleStrategy['strategy_name'], E_USER_NOTICE);<\/pre>\n<p>&nbsp;<\/p>\n<h2>Twitter\u8a2d\u5b9a<\/h2>\n<p><a href=\"https:\/\/apps.twitter.com\/\" target=\"_blank\" rel=\"noopener\">https:\/\/apps.twitter.com\/<\/a><\/p>\n<p>\u4e0a\u8a18\u30da\u30fc\u30b8\u304b\u3089\u30ed\u30b0\u30a4\u30f3\u3057\u3001\u300cCreate New App\u300d\u3092\u30af\u30ea\u30c3\u30af\u3057\u6b21\u306e\u753b\u9762\u3067\u5404\u9805\u76ee\u3092\u5165\u529b\u3059\u308b\u3002<\/p>\n<p>Website\u3068Callback URLs\u306f\u4eca\u56de\u3060\u3068\u300chttp:\/\/test.com\/user\/login\u300d\u3092\u5165\u308c\u3066\u304a\u3051\u3070\u3088\u3044\u3002<\/p>\n<p>\u4f5c\u6210\u6210\u529f\u3059\u308b\u3068\u30da\u30fc\u30b8\u9077\u79fb\u3059\u308b\u306e\u3067Consumer Key(API Key)\u306e\u53f3\u306b\u3042\u308b\u300cmanage keys and access tokens\u300d\u30ea\u30f3\u30af\u3092\u30af\u30ea\u30c3\u30af\u3059\u308b\u3068API Key\u3068API Secret\u304c\u53d6\u5f97\u3067\u304d\u308b\u3002<\/p>\n<p>\u3053\u308c\u3092opauth.conf.php\u306b\u8ffd\u8a18\u3059\u308b\u3002<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">'Strategy' =&gt; array(\r\n    'Twitter' =&gt; array(\r\n        'key' =&gt; 'API Key',\r\n        'secret' =&gt; 'API Secret',\r\n    ),\r\n),<\/pre>\n<p>\u307e\u305ftwitter\u306eSetting\u30bf\u30d6\u5185\u306b\u3042\u308b\u4e0b\u90e8\u306e\u300cEnable Callback Locking (It is recommended to enable callback locking to ensure apps cannot overwrite the callback url)\u300d\u306e\u30c1\u30a7\u30c3\u30af\u3092\u5916\u3057\u3066\u300cUpdate Settings\u300d\u3067\u4e0a\u66f8\u304d\u3057\u3066\u304a\u304f\u3002<\/p>\n<p>login\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306eindex.php\u3092\u7de8\u96c6\u3059\u308b\u3002<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">&lt;a href=\".\/twitter\"&gt;twitter&lt;\/a&gt;<\/pre>\n<p>\u30af\u30ea\u30c3\u30af\u3059\u308b\u3068Twitter\u306e\u30bd\u30fc\u30b7\u30e3\u30eb\u30ed\u30b0\u30a4\u30f3\u304c\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u3063\u3066\u3044\u308b\u306f\u305a\u3002<\/p>\n<p>&nbsp;<\/p>\n<h2>Google\u8a2d\u5b9a<\/h2>\n<p><a href=\"https:\/\/console.developers.google.com\/apis\/library\" target=\"_blank\" rel=\"noopener\">https:\/\/console.developers.google.com\/apis\/library<\/a><\/p>\n<p>\u4e0a\u8a18\u30da\u30fc\u30b8\u3088\u308a\u30ed\u30b0\u30a4\u30f3\u3057\u3001\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3092\u65b0\u898f\u4f5c\u6210\u3059\u308b\u3002<\/p>\n<p>\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u540d\u3092\u5165\u308c\u3001\u7d44\u7e54\u540d\u90e8\u5206\u306f\u305d\u306e\u307e\u307e\u3067\u4f5c\u6210\u3092\u30af\u30ea\u30c3\u30af\u3059\u308b\u3002<\/p>\n<p>\u30c0\u30c3\u30b7\u30e5\u30dc\u30fc\u30c9\u306e\u9078\u629e\u3092\u30af\u30ea\u30c3\u30af\u3057\u3001\u5148\u307b\u3069\u4f5c\u6210\u3057\u305f\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3092\u9078\u629e\u3059\u308b\u3002<\/p>\n<p>\u8a8d\u8a3c\u60c5\u5831\u2192OAuth\u540c\u610f\u753b\u9762\u306b\u9032\u307f\u3001\u5404\u9805\u76ee\u3092\u5165\u529b\u3059\u308b\u3002\u30b5\u30fc\u30d3\u30b9\u540d\u3060\u3051\u3067\u4ed6\u306f\u7701\u7565\u53ef\u80fd\u3002<\/p>\n<p>\u8a8d\u8a3c\u60c5\u5831\u30bf\u30d6\u3067\u8a8d\u8a3c\u60c5\u5831\u3092\u4f5c\u6210\u30dc\u30bf\u30f3\u3092\u30af\u30ea\u30c3\u30af\u3001OAuth \u30af\u30e9\u30a4\u30a2\u30f3\u30c8 ID\u3092\u9078\u629e\u3059\u308b\u3002<\/p>\n<p>\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u306e\u7a2e\u985e\u306f\u300c\u30a6\u30a7\u30d6\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u300d\u3001\u540d\u524d\u306f\u9069\u5b9c\u5165\u529b\u3001\u627f\u8a8d\u6e08\u307f\u306e\u30ea\u30c0\u30a4\u30ec\u30af\u30c8URI\u306f\u4eca\u56de\u306e\u5834\u5408\u3060\u3068\u300chttp:\/\/test.com\/user\/login\/google\/oauth2callback\u300d\u3067\u5165\u529b\u3057\u3001\u4f5c\u6210\u3059\u308b\u3002<\/p>\n<p>\u5b8c\u4e86\u3059\u308b\u3068\u30af\u30e9\u30a4\u30a2\u30f3\u30c8ID\u3068\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u30b7\u30fc\u30af\u30ec\u30c3\u30c8\u304c\u767a\u884c\u3055\u308c\u308b\u306e\u3067opauth.conf.php\u306b\u8ffd\u8a18\u3059\u308b\u3002<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">'Strategy' =&gt; array(\r\n    'Google' =&gt; array(\r\n        'client_id' =&gt; '\u30af\u30e9\u30a4\u30a2\u30f3\u30c8ID',\r\n        'client_secret' =&gt; '\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u30b7\u30fc\u30af\u30ec\u30c3\u30c8'\r\n    ),\r\n),<\/pre>\n<p>login\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306eindex.php\u3092\u7de8\u96c6\u3059\u308b\u3002<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">&lt;a href=\".\/google\"&gt;google&lt;\/a&gt;<\/pre>\n<p>\u30af\u30ea\u30c3\u30af\u3059\u308b\u3068Google\u306e\u30bd\u30fc\u30b7\u30e3\u30eb\u30ed\u30b0\u30a4\u30f3\u304c\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u3063\u3066\u3044\u308b\u306f\u305a\u3002<\/p>\n<p>&nbsp;<\/p>\n<h2>Facebook\u8a2d\u5b9a<\/h2>\n<p><a href=\"https:\/\/developers.facebook.com\" target=\"_blank\" rel=\"noopener\">https:\/\/developers.facebook.com<\/a><\/p>\n<p>\u4e0a\u8a18\u30da\u30fc\u30b8\u3088\u308a\u30ed\u30b0\u30a4\u30f3\u3057\u3001\u30de\u30a4\u30a2\u30d7\u30ea\u2192\u65b0\u3057\u3044\u30a2\u30d7\u30ea\u3092\u8ffd\u52a0\u306b\u9032\u3080\u3002<\/p>\n<p>\u8868\u793a\u540d\u3092\u5165\u529b\u3057\u3066\u30a2\u30d7\u30ea\u3092\u4f5c\u6210\u3059\u308b\u3002<\/p>\n<p>\u30c0\u30c3\u30b7\u30e5\u30dc\u30fc\u30c9\u304b\u3089Facebook\u30ed\u30b0\u30a4\u30f3\u3067\u8a2d\u5b9a\u3092\u30af\u30ea\u30c3\u30af\u3059\u308b\u3002<\/p>\n<p>Facebook\u30ed\u30b0\u30a4\u30f3\u2192\u8a2d\u5b9a\u306b\u9032\u307f\u3001\u6709\u52b9\u306aOAuth\u30ea\u30c0\u30a4\u30ec\u30af\u30c8URI\u3092\u5165\u308c\u308b\u3002\u4eca\u56de\u306e\u5834\u5408\u3060\u3068\u300chttp:\/\/test.com\/user\/login\/facebook\/int_callback\u300d\u306b\u306a\u308b\u3002\u4ed6\u306f\u305d\u306e\u307e\u307e\u3067\u4fdd\u5b58\u3059\u308b\u3002<\/p>\n<p>\u8a2d\u5b9a\u2192\u30d9\u30fc\u30b7\u30c3\u30af\u306b\u9032\u307f\u30a2\u30d7\u30ea\u30c9\u30e1\u30a4\u30f3\u3001\u30d7\u30e9\u30a4\u30d0\u30b7\u30fc\u30dd\u30ea\u30b7\u30fc\u306eURL\u3001\u5229\u7528\u898f\u7d04\u306eURL\u3001\u30ab\u30c6\u30b4\u30ea\u3092\u9078\u629e\u3057\u3066\u4fdd\u5b58\u3059\u308b\u3002<\/p>\n<p>\u30da\u30fc\u30b8\u4e0a\u90e8\u306e\u30b9\u30c6\u30fc\u30bf\u30b9\u3092\u30aa\u30f3\u306b\u5909\u66f4\u3059\u308b\u3002<\/p>\n<p>\u8a2d\u5b9a\u2192\u30d9\u30fc\u30b7\u30c3\u30af\u306b\u9032\u307f\u30a2\u30d7\u30eaID\u3068app secret\u3092opauth.conf.php\u306b\u8ffd\u8a18\u3059\u308b\u3002<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">'Strategy' =&gt; array(\r\n    'Facebook' =&gt; array(\r\n        'app_id' =&gt; '\u30a2\u30d7\u30eaID',\r\n        'app_secret' =&gt; 'app secret',\r\n    ),\r\n),<\/pre>\n<p>login\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306eindex.php\u3092\u7de8\u96c6\u3059\u308b\u3002<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">&lt;a href=\".\/facebook\"&gt;facebook&lt;\/a&gt;<\/pre>\n<p>\u30af\u30ea\u30c3\u30af\u3059\u308b\u3068facebook\u306e\u30bd\u30fc\u30b7\u30e3\u30eb\u30ed\u30b0\u30a4\u30f3\u304c\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u3063\u3066\u3044\u308b\u306f\u305a\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e45\u3057\u3076\u308a\u306b\u30bd\u30fc\u30b7\u30e3\u30eb(SNS)\u30ed\u30b0\u30a4\u30f3\u3092\u5b9f\u88c5\u3059\u308b\u6a5f\u4f1a\u304c\u3042\u3063\u305f\u3002\u4ee5\u524d\u306b\u5bfe\u5fdc\u65b9\u6cd5\u3092\u66f8 ... <\/p>\n","protected":false},"author":1,"featured_media":1085,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[2],"tags":[],"class_list":["post-3002","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-php"],"acf":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/posts\/3002","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/comments?post=3002"}],"version-history":[{"count":3,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/posts\/3002\/revisions"}],"predecessor-version":[{"id":4798,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/posts\/3002\/revisions\/4798"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/media\/1085"}],"wp:attachment":[{"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/media?parent=3002"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/categories?post=3002"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/tags?post=3002"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}