{"id":1619,"date":"2017-04-21T00:01:22","date_gmt":"2017-04-20T15:01:22","guid":{"rendered":"http:\/\/lovelinux.mydns.jp\/?p=1619"},"modified":"2017-04-21T00:06:41","modified_gmt":"2017-04-20T15:06:41","slug":"react%e3%81%a7spa%e3%82%92%e4%bd%9c%e3%82%8a%e3%80%81twitter%e8%aa%8d%e8%a8%bc%e3%81%a7%e3%83%ad%e3%82%b0%e3%82%a4%e3%83%b3%e3%81%99%e3%82%8b%e3%80%82%e3%83%90%e3%83%83%e3%82%af%e3%82%a8%e3%83%b3","status":"publish","type":"post","link":"https:\/\/lovelinux.mydns.jp\/?p=1619","title":{"rendered":"React\u3067SPA\u3092\u4f5c\u308a\u3001Twitter\u8a8d\u8a3c(OAuth)\u3067\u30ed\u30b0\u30a4\u30f3\u3059\u308b\u3002\u30d0\u30c3\u30af\u30a8\u30f3\u30c9\u306fRails"},"content":{"rendered":"<h3>\u306f\u3058\u3081\u306b<\/h3>\n<p>React\u3067SPA\u3092\u4f5c\u308b\u3053\u3068\u306b\u306a\u3063\u3066\u3001\u30ed\u30b0\u30a4\u30f3\u8a8d\u8a3c\u306b\u30e1\u30fc\u30eb\uff06\u30d1\u30b9\u30ef\u30fc\u30c9\u306e\u8a8d\u8a3c\u306b\u52a0\u3048\u3066\u3001<br \/>\nGoogle\u3084Twitter\u8a8d\u8a3c\u3082\u52a0\u3048\u305f\u304f\u306a\u3063\u305f\u6642\u3001\u3069\u3046\u3059\u308c\u3070\u3088\u3044\u304b\u308f\u304b\u3089\u306a\u304b\u3063\u305f\u3002<br \/>\n\u30d0\u30c3\u30af\u30a8\u30f3\u30c9\u306fRails\u3060\u304c\u3001\u3042\u304f\u307e\u3067API\u30b5\u30fc\u30d0\u30fc\u7684\u306a\u7acb\u5834\u306a\u306e\u3067 \u30e1\u30b8\u30e3\u30fc\u306aomniauth<br \/>\n\u306a\u3093\u304b\u306f\u4f7f\u3048\u305d\u3046\u306b\u306a\u3044\u3002\u3002\u3002<br \/>\n<a href=\"http:\/\/lovelinux.mydns.jp\/?p=1608\">\u524d\u56de\u306eGoogle\u7de8\u306b\u7d9a\u304d<\/a>\u3001\u4eca\u56de\u306fTwitter\u7de8\u3002<br \/>\n\u3042\u308c\u3053\u308c\u60a9\u307f\u306a\u304c\u3089\u306a\u3093\u3068\u304b\u52d5\u304f\u3068\u3053\u308d\u307e\u3067\u305f\u3069\u308a\u7740\u3044\u305f\u306e\u3067\u3001\u3084\u308a\u65b9\u3092\u516c\u958b\u3002<\/p>\n<p>React+Redux\u306e\u74b0\u5883\u306a\u3093\u3067\u3059\u304c\u3001\u305d\u3053\u307e\u3067\u7acb\u3061\u5165\u308b\u3068\u8a71\u304c\u3084\u3084\u3053\u3057\u304f\u306a\u308b\u306e\u3067\u3001<br \/>\n\u5b9f\u88c5\u306e\u30a8\u30ad\u30b9\u90e8\u5206\u3060\u3051\u3092\u8a18\u8f09\u3057\u3066\u307f\u307e\u3059\u3002<\/p>\n<h3>Twitter Developer\u306b\u30a2\u30d7\u30ea\u767b\u9332<\/h3>\n<p><a href=\"https:\/\/dev.twitter.com\/\">Twitter Developer<\/a><\/p>\n<p>\u3053\u308c\u306b\u3064\u3044\u3066\u306f\u4e0a\u8a18\u306eURL\u306b\u30a2\u30af\u30bb\u30b9\u3057\u3066\u30a2\u30d7\u30ea\u3092\u767b\u9332\u3057\u3066\u304f\u3060\u3055\u3044\u3002<br \/>\n\u30a2\u30d7\u30ea\u540d\u3068\u30b3\u30fc\u30eb\u30d0\u30c3\u30afURL\u3092\u767b\u9332\u3057\u305f\u3089\u3001Consumer Key (API Key)\u3068Consumer Secret (API Secret)\u304c\u3082\u3089\u3048\u307e\u3059\u3002<br \/>\n\u8a73\u3057\u304f\u306f\u66f8\u304d\u307e\u305b\u3093\u3001\u30b0\u30b0\u308c\u3070\u3053\u308c\u306f\u305f\u304f\u3055\u3093\u66f8\u3044\u3066\u3042\u308a\u307e\u3059\u3002<\/p>\n<p><a href=\"http:\/\/lovelinux.mydns.jp\/wp-content\/uploads\/2017\/04\/oauth-15.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/lovelinux.mydns.jp\/wp-content\/uploads\/2017\/04\/oauth-15.png\" alt=\"oauth-15\" width=\"745\" height=\"729\" class=\"alignnone size-full wp-image-1628\" \/><\/a><\/p>\n<h3>\u52d5\u4f5c\u30a4\u30e1\u30fc\u30b8<\/h3>\n<p>\u30c7\u30b6\u30a4\u30f3\u306f\u3057\u3087\u307c\u3044\u3067\u3059\u304c\u3001\u3053\u3093\u306a\u611f\u3058\u306e\u30ed\u30b0\u30a4\u30f3\u753b\u9762\u3002<br \/>\nGoogle\u304bTwitter\u3067\u8a8d\u8a3c\u3057\u3066\u30ed\u30b0\u30a4\u30f3\u3057\u3066\u306d\u3001\u3068\u3044\u3046\u3082\u306e\u3002<br \/>\n\u4eca\u56de\u306fTwitter\u306b\u3064\u3044\u3066\u306e\u307f\u53d6\u308a\u4e0a\u3052\u307e\u3059\u3002<\/p>\n<p>Twitter\u3067\u30ed\u30b0\u30a4\u30f3\u3092\u30af\u30ea\u30c3\u30af\u3059\u308b\u3068\u3001Twitter\u304c\u7528\u610f\u3057\u3066\u3044\u308bOAuth\u7528\u306e\u753b\u9762\u304c\u8868\u793a\u3055\u308c\u3066\u3001<br \/>\nTwitter\u306e\u30e6\u30fc\u30b6\u30fc\u540d\u3068\u30d1\u30b9\u30ef\u30fc\u30c9\u3092\u5165\u308c\u3066\u3001\u6700\u5f8c\u306b\u4eca\u56de\u4f5c\u308b\u30a2\u30d7\u30ea\uff08SPA\uff09\u3078\u306e\u30a2\u30af\u30bb\u30b9\u8a31\u53ef\u753b\u9762\u304c\u8868\u793a\u3055\u308c\u3001<br \/>\n\u8a31\u53ef\u3059\u308b\u3068\u3001SPA\u30a2\u30d7\u30ea\u306b\u30ed\u30b0\u30a4\u30f3\u51fa\u6765\u308b\u3068\u3044\u3046\u3082\u306e\u3002<\/p>\n<p><a href=\"http:\/\/lovelinux.mydns.jp\/wp-content\/uploads\/2017\/04\/oauth-1.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/lovelinux.mydns.jp\/wp-content\/uploads\/2017\/04\/oauth-1.png\" alt=\"oauth-1\" width=\"618\" height=\"351\" class=\"alignnone size-full wp-image-1610\" \/><\/a><\/p>\n<p><a href=\"http:\/\/lovelinux.mydns.jp\/wp-content\/uploads\/2017\/04\/oauth-12.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/lovelinux.mydns.jp\/wp-content\/uploads\/2017\/04\/oauth-12.png\" alt=\"oauth-12\" width=\"741\" height=\"710\" class=\"alignnone size-full wp-image-1623\" \/><\/a><\/p>\n<p><a href=\"http:\/\/lovelinux.mydns.jp\/wp-content\/uploads\/2017\/04\/oauth-11.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/lovelinux.mydns.jp\/wp-content\/uploads\/2017\/04\/oauth-11.png\" alt=\"oauth-11\" width=\"789\" height=\"639\" class=\"alignnone size-full wp-image-1622\" \/><\/a><\/p>\n<p><a href=\"http:\/\/lovelinux.mydns.jp\/wp-content\/uploads\/2017\/04\/oauth-5.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/lovelinux.mydns.jp\/wp-content\/uploads\/2017\/04\/oauth-5.png\" alt=\"oauth-5\" width=\"681\" height=\"402\" class=\"alignnone size-full wp-image-1614\" \/><\/a><\/p>\n<h3>\u30b9\u30c6\u30c3\u30d7\uff11(Javascript\u3001Ajax)<\/h3>\n<p>\u307e\u305a\u306f<br \/>\n\u307e\u305a\u306fTwitter\u306eOAuth\u7528URL\u306e\u53d6\u5f97\u306e\u305f\u3081\u306eRails API\uff08\u81ea\u4f5c\uff09\u547c\u3073\u51fa\u3057\u3002<br \/>\nReact\u306e\u66f8\u304d\u65b9\u306a\u306e\u3067\u3001function\u3089\u3057\u304f\u306a\u3044\u3067\u3059\u304c\u30fb\u30fb\u30fb\u305f\u3060\u306efunction\u3060\u3068\u601d\u3063\u3066\u30bd\u30fc\u30b9\u3092\u898b\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<p>API\u547c\u3073\u51fa\u3057\u306e\u7d50\u679c\u3001OAuth\u7528\u306eURL\u304c\u5f97\u3089\u308c\u308b\u306e\u3067\u3001window.open\u3059\u308b\u611f\u3058\u3067\u3059\u3002<br \/>\n\u30dd\u30c3\u30d7\u30a2\u30c3\u30d7\u3068\u3044\u3046\u304b\u5225\u30bf\u30d6\u3067Twitter\u306eOAuth\u753b\u9762\u304c\u958b\u304d\u307e\u3059\u3002<br \/>\n\u3067\u3001window.open\u3057\u305f\u3042\u3068\u306f setTimeout\u30671\u79d2\u304a\u304d\u306b\u30a6\u30a3\u30f3\u30c9\u30a6\u304c\u9589\u3058\u305f\u304b\u3069\u3046\u304b\u3092\u30c1\u30a7\u30c3\u30af\u3057\u307e\u3059\u3002<\/p>\n<p>[bash]<br \/>\n    onLoginTwitter: (history) => {<br \/>\n      axios.get(&#8220;http:\/\/localhost:3000\/get_twitter_oauth_url&#8221;, {<br \/>\n          withCredentials: true,<br \/>\n      \t\tparams: {}<br \/>\n      \t})<br \/>\n      \t.then(function (response) {<br \/>\n          windowLogin = window.open(response.data.oauth_url)<br \/>\n          setTimeout(function(){CheckLoginStatusTwitter(history)}, 1000)<br \/>\n          windowLogin.focus()<br \/>\n      \t})<br \/>\n      \t.catch(function (response) {<br \/>\n      \t\tconsole.log(response);<br \/>\n      \t});<br \/>\n    }<\/p>\n<p>[\/bash]<\/p>\n<h3>\u30b9\u30c6\u30c3\u30d7\uff11\uff0e\uff15(Rails)<\/h3>\n<p>\u30b9\u30c6\u30c3\u30d7\uff11\u304b\u3089\u547c\u3073\u51fa\u3055\u308c\u308bRails\u306e\u30bd\u30fc\u30b9\u3002<br \/>\nCONSUMER_ID\u3068CONSUMER_SECRET\u3092\u7528\u3044\u3066\u3001OAuth\u7528\u306eURL\u3092\u53d6\u5f97\u3057\u3001JSON\u3067\u7d50\u679c\u3092\u623b\u3057\u307e\u3059\u3002<\/p>\n<p>[bash]<br \/>\n  require &#8216;oauth&#8217;<\/p>\n<p>  def get_twitter_oauth_url<br \/>\n    consumer = OAuth::Consumer.new(<br \/>\n      Oauth::TWITTER_CONSUMER_ID,<br \/>\n      Oauth::TWITTER_CONSUMER_SECRET,<br \/>\n      { :site => &#8220;https:\/\/api.twitter.com&#8221; }<br \/>\n    )<\/p>\n<p>    request_token = consumer.get_request_token(<br \/>\n      :oauth_callback => &#8220;http:\/\/localhost:3000\/oauth_twitter&#8221;<br \/>\n    )<\/p>\n<p>    cookies[:request_token] = request_token.token<br \/>\n    cookies[:request_token_secret] = request_token.secret<\/p>\n<p>    rtn = {}<br \/>\n    rtn[&#8220;status&#8221;] = true<br \/>\n    rtn[&#8220;oauth_url&#8221;] = request_token.authorize_url<\/p>\n<p>    render json: rtn<br \/>\n  end<\/p>\n<p>[\/bash]<\/p>\n<h3>\u30b9\u30c6\u30c3\u30d7\uff12(Javascript)<\/h3>\n<p>\u30b9\u30c6\u30c3\u30d7\uff11\u306e\u30bd\u30fc\u30b9\u306eWindow\u547c\u3073\u51fa\u3057\u306e\u3068\u3053\u308d\u3060\u3051\u3092\u629c\u7c8b\u3002<br \/>\nRails\u306eAPI\u3067\u623b\u3063\u3066\u304d\u305f\u8a8d\u8a3c\u7528URL\u3092\u5f15\u6570\u306b\u3057\u3066 window.open\u3002<\/p>\n<p>[bash]<br \/>\nwindowLogin = window.open(response.data.oauth_url)<br \/>\n[\/bash]<\/p>\n<h3>\u30b9\u30c6\u30c3\u30d7\uff13<\/h3>\n<p>\u3053\u3053\u306f\u30d7\u30ed\u30b0\u30e9\u30e0\u3059\u308b\u5fc5\u8981\u306a\u3057\u3067\u3059\u3002Twitter\u306eOAuth\u306e\u753b\u9762\u3067<br \/>\n\u7d14\u7c8b\u306b\u8a8d\u8a3c\uff06\u8a31\u53ef\u3092\u3057\u3066\u3082\u3089\u3044\u307e\u3059\u3002<\/p>\n<h3>\u30b9\u30c6\u30c3\u30d7\uff14(Rails)<\/h3>\n<p>Twitter\u5074\u306e\u8a8d\u8a3c\u3068\u8a31\u53ef\u306e\u51e6\u7406\u304c\u7d42\u308f\u308b\u3068\u3001\u30b9\u30c6\u30c3\u30d7\uff11\uff0e\uff15\u3067\u6307\u5b9a\u3057\u305f\u30b3\u30fc\u30eb\u30d0\u30c3\u30afURL\u306b\u5236\u5fa1\u304c\u623b\u3063\u3066\u304d\u307e\u3059\u3002<br \/>\n\u30c6\u30b9\u30c8\u74b0\u5883\u3067\u3059\u306e\u3067Rails\u306e\u30c7\u30d5\u30a9\u30eb\u30c8 http:\/\/localhost:3000 \u3067\u30b5\u30fc\u30d0\u30fc\u304c\u7acb\u3061\u4e0a\u304c\u3063\u3066\u3044\u3066\u3001<br \/>\n\u30b3\u30fc\u30eb\u30d0\u30c3\u30afURL\u306f\u3000http:\/\/localhost:3000\/oauth_twitter\u3000\u3067\u3059\u3002<\/p>\n<p>\u3067\u306f\u3001Rails\u306e\u65b9\u306e\u5b9f\u88c5\u3092\u898b\u3066\u307f\u307e\u3057\u3087\u3046\u3002<br \/>\n\u6700\u521d\u306bCONSUMER_ID\u3068CONSUMER_SECRET\u3092\u7528\u3044\u3066\u3001\u30c8\u30fc\u30af\u30f3\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002<br \/>\n\u3055\u3089\u306b\u3001\u30d1\u30e9\u30e1\u30fc\u30bf\u30fc\u3067\u6e21\u3063\u3066\u304d\u305f\u3001 oauth_token\u3068oauth_verifier\u3092\u4f7f\u3063\u3066<br \/>\n\u30a2\u30af\u30bb\u30b9\u30c8\u30fc\u30af\u30f3\u3092\u5f97\u307e\u3059\u3002<br \/>\n\u6700\u5f8c\u306b\u5f97\u3089\u308c\u305f\u30a2\u30af\u30bb\u30b9\u30c8\u30fc\u30af\u30f3\u3092\u4f7f\u3063\u3066API\u30a2\u30af\u30bb\u30b9\u3057\u3001\u30e6\u30fc\u30b6\u30fc\u60c5\u5831\u3092\u5f97\u307e\u3059\u3002<\/p>\n<p>\u3067\u3001cookies\u306b\u5f97\u3089\u308c\u305f\u60c5\u5831\u3092\u30bb\u30c3\u30c8\u3057\u3066\u3001\u3053\u306e\u30e1\u30bd\u30c3\u30c9\u3092\u629c\u3051\u307e\u3059\u3002<\/p>\n<p>  cookies[:oauth_token] = params[:oauth_token]<br \/>\n  cookies[:twitter_uid] = user_info[&#8220;id&#8221;]<br \/>\n  cookies[:screen_name] = user_info[&#8220;screen_name&#8221;]<\/p>\n<p>[bash]<br \/>\nclass OauthController < ApplicationController\n  #URL \/oauth_twitter \u3078\u306e\u51e6\u7406\n  def twitter\n    consumer = OAuth::Consumer.new(\n      Oauth::TWITTER_CONSUMER_ID,\n      Oauth::TWITTER_CONSUMER_SECRET,\n      { :site => &#8220;https:\/\/api.twitter.com&#8221; }<br \/>\n    )<\/p>\n<p>    request_token = OAuth::RequestToken.new(<br \/>\n      consumer,<br \/>\n      cookies[:request_token],<br \/>\n      cookies[:request_token_secret]<br \/>\n    )<\/p>\n<p>    access_token = request_token.get_access_token(<br \/>\n      {},<br \/>\n      :oauth_token => params[:oauth_token],<br \/>\n      :oauth_verifier => params[:oauth_verifier]<br \/>\n    )<\/p>\n<p>    response = consumer.request(<br \/>\n      :get,<br \/>\n      &#8216;\/1.1\/account\/verify_credentials.json&#8217;,<br \/>\n      access_token, { :scheme => :query_string }<br \/>\n    )<\/p>\n<p>    rtn = {}<\/p>\n<p>    case response<br \/>\n    when Net::HTTPSuccess<br \/>\n      user_info = JSON.parse(response.body)<\/p>\n<p>      if user_info[&#8220;screen_name&#8221;]<br \/>\n        cookies[:oauth_token] = params[:oauth_token]<br \/>\n        cookies[:twitter_uid] = user_info[&#8220;id&#8221;]<br \/>\n        cookies[:screen_name] = user_info[&#8220;screen_name&#8221;]<br \/>\n      else<br \/>\n        #&#8221;Authentication failed&#8221;<br \/>\n      end<br \/>\n    else<br \/>\n        #&#8221;Failed to get user info via OAuth&#8221;<br \/>\n    end<\/p>\n<p>  end<\/p>\n<p>end<\/p>\n<p>[\/bash]<\/p>\n<p>Rails\u306eGemfile\u306b\u4ee5\u4e0b\u306e\uff13\u3064\u306egem\u3092\u8ffd\u52a0\u3057\u307e\u3059\u3002<\/p>\n<p>[bash]<br \/>\ngem &#8216;json&#8217;<br \/>\ngem &#8216;oauth&#8217;<br \/>\ngem &#8216;rack-cors&#8217;, :require => &#8216;rack\/cors&#8217;<\/p>\n<p>[\/bash]<\/p>\n<p>SPA\u3092\u30b5\u30fc\u30d6\u3057\u3066\u3044\u308b\u30b5\u30fc\u30d0\u30fc\u3068API\u3092\u30b5\u30fc\u30d6\u3057\u3066\u3044\u308b\u30b5\u30fc\u30d0\u30fc\u304c\u5225\u7269\u306b\u306a\u308b\u306e\u3067\u3001<br \/>\n\u30af\u30ed\u30b9\u30c9\u30e1\u30a4\u30f3\u306aAPI\u30a2\u30af\u30bb\u30b9\u3068\u306a\u308b\u305f\u3081\u3001API\u5074\u3067\u305d\u308c\u3092\u8a31\u53ef\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<br \/>\ngem rack-cors \u3067\u305d\u308c\u306b\u5bfe\u5fdc\u3067\u304d\u307e\u3059\u3002\u3067\u3001\u5bfe\u5fdc\u3059\u308b\u305f\u3081\u306bapplication.rb\u3092<br \/>\n\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u66f8\u304d\u63db\u3048\u307e\u3059\u3002\u3000\u672c\u756a\u3067\u306forigins\u306f\u300c\uff0a\u300d\u3067\u306f\u306a\u304f\u3001\u3061\u3083\u3093\u3068\u7279\u5b9a\u306e\u30c9\u30e1\u30a4\u30f3\u540d\u3092\u5165\u308c\u308b\u3079\u3057\u3002<\/p>\n<p>config\/application.rb<br \/>\n[bash]<br \/>\n  class Application < Rails::Application\n\n    config.middleware.insert_before ActionDispatch::Static, Rack::Cors do\n      allow do\n        origins '*'\n        resource '*', :headers => :any, :methods => [:get, :post, :delete]<br \/>\n      end<br \/>\n    end<\/p>\n<p>  end<\/p>\n<p>[\/bash]<\/p>\n<h3>\u30b9\u30c6\u30c3\u30d7\uff15(Rails\u306eJavascript)<\/h3>\n<p>OauthController\u306etwitter\u30e1\u30bd\u30c3\u30c9\u3067\u51e6\u7406\u3092\u3057\u305f\u306e\u3067\u3001\u666e\u901a\u306b\u51e6\u7406\u304c\u7d42\u308f\u308c\u3070\u3001\u30dd\u30c3\u30d7\u30a2\u30c3\u30d7\u753b\u9762\u306b\u306f<br \/>\n\u305d\u306e\u30e1\u30bd\u30c3\u30c9\u306b\u5bfe\u5fdc\u3059\u308b\u30d3\u30e5\u30fc\u304c\u8868\u793a\u3055\u308c\u307e\u3059\u3002<br \/>\n\u306a\u306e\u3067\u3001\u5bfe\u5fdc\u3059\u308b\u30d3\u30e5\u30fc\u306f\u4f5c\u308b\u306e\u3067\u3059\u304c\u3001\u3042\u304f\u307e\u3067\u30c0\u30df\u30fc\u3067\u7d50\u69cb\u3067\u3059\u3002<br \/>\n\u305d\u3082\u305d\u3082\u3001\u30dd\u30c3\u30d7\u30a2\u30c3\u30d7\uff08\u5225\u30bf\u30d6\uff09\u3067Twitter\u8a8d\u8a3c\u304c\u958b\u3044\u3066\u3044\u3066\u3001\u8a8d\u8a3c\u304c\u7d42\u308f\u308c\u3070\u30dd\u30c3\u30d7\u30a2\u30c3\u30d7\u306f\u9589\u3058\u3066\u307b\u3057\u3044<br \/>\n\u306f\u305a\u3067\u3059\u306e\u3067\u30fb\u30fb\u30fb<\/p>\n<p>\u3067\u3001assets\/javascripts \u914d\u4e0b\u306b\u4ee5\u4e0b\u306e\u3088\u3046\u306aJavaScript\uff08CoffeeScript\u3067\u306f\u306a\u3044\uff09\u3092\u4f5c\u308a\u307e\u3059\u3002<br \/>\n\u30d5\u30a1\u30a4\u30eb\u540d\u306f\u306a\u3093\u3067\u3082\u3044\u3044\u3002<br \/>\n\u3067\u3001\u3053\u3053\u3067\u3059\u308b\u51e6\u7406\u306f\u3001\u30c0\u30df\u30fc\u306e\u30d3\u30e5\u30fc\u304c\u8868\u793a\u3055\u308c\u305f\u6642\u306b\u305d\u306ehref\u3092\u30c1\u30a7\u30c3\u30af\u3057\u3066\u3001<br \/>\n\u8a8d\u8a3c\u7d42\u4e86\u306e\u30c0\u30df\u30fc\u30d3\u30e5\u30fc\u3060\u3068\u5224\u5b9a\u3067\u304d\u305f\u3089\u3001window.close\u3057\u3066\u3084\u308b\u3068\u3044\u3046\u3082\u306e\u3067\u3059\u3002<\/p>\n<p>[bash]<br \/>\n$(function(){<br \/>\n  if (window.location.href.indexOf(&#8220;oauth_twitter&#8221;) >0){<br \/>\n    window.close();<br \/>\n  }<\/p>\n<p>});<\/p>\n<p>[\/bash]<\/p>\n<h3>\u30b9\u30c6\u30c3\u30d7\uff16(SPA\u306eJavascript)<\/h3>\n<p>\u6700\u5f8c\u306b\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u30b5\u30a4\u30c9\u3067\u3059\u3002window.open\u306e\u6642\u306bsetTimeout\u3067\u547c\u3070\u308c\u308b\u30e1\u30bd\u30c3\u30c9\u3067\u3059\u3002<br \/>\nwindowLogin.closed\u306e\u72b6\u614b\u3092\uff11\u79d2\u9593\u9694\u3067\u30c1\u30a7\u30c3\u30af\u3057\u3001Twitter\u306e\u8a8d\u8a3c\u753b\u9762\u304c\u9589\u3058\u305f\u3089<br \/>\nalert\u306b\u8a8d\u8a3c\u3067\u5f97\u3089\u308c\u305f\u60c5\u5831\u3092\u30af\u30c3\u30ad\u30fc\u304b\u3089\u8868\u793a\u3057\u307e\u3059\u3002\uff08\u5225\u306b\u8868\u793a\u3059\u308b\u5fc5\u8981\u306f\u306a\u3044\u306e\u3067\u3059\u304c\u30fb\u30fb\u30fb\uff09<br \/>\n\u3067\u3001\u8a8d\u8a3c\u304c\u901a\u3063\u305f\u3068\u5224\u5b9a\u3067\u304d\u305f\u3089\u3001\u30a2\u30d7\u30ea\u306e\u30c8\u30c3\u30d7\u30da\u30fc\u30b8\u306a\u3069\u3078\u30b8\u30e3\u30f3\u30d7\u3057\u3066\u3084\u308a\u307e\u3059\u3002<\/p>\n<p>\u3042\u3068\u306fSPA\u306a\u306e\u3067API\u30b5\u30fc\u30d0\u30fc\u3078\u30a2\u30af\u30bb\u30b9\u3059\u308b\u305f\u3073\u306b\u304a\u305d\u3089\u304f\u30e6\u30fc\u30b6\u30fc\u8a8d\u8a3c\u3082\u5fc5\u305a\u3059\u308b\u3053\u3068\u306b\u306a\u308b\u3068\u601d\u3046\u306e\u3067\u3001<br \/>\nAPI\u3092\u547c\u3076\u305f\u3073\u306b\u3001\u3053\u3053\u3067\u5f97\u3089\u308c\u305f\u60c5\u5831\u3092\u4ed8\u4e0e\u3057\u3066\u3084\u308b\u30a4\u30e1\u30fc\u30b8\u3067\u3057\u3087\u3046\u304b\u30fb\u30fb\u30fb<\/p>\n<p>\u672c\u984c\u3068\u306f\u305d\u308c\u307e\u3059\u304c\u3001setTimeout\u3067\u5f15\u6570\u3092\u3064\u3051\u305ffunction\u3092\u547c\u3073\u305f\u3044\u3068\u304d\u306f \u7121\u540d\u95a2\u6570\u3068\u3059\u308b<br \/>\n\u306e\u304c\u30eb\u30fc\u30eb\u306e\u3088\u3046\u3067\u3059\u3002<\/p>\n<p>[bash]<br \/>\nconst CheckLoginStatusTwitter = (history) => {<br \/>\n  if (windowLogin.closed) {<br \/>\n    alert(Cookies.get(&#8216;twitter_uid&#8217;) + &#8220;\\n&#8221; + Cookies.get(&#8216;screen_name&#8217;))<br \/>\n    if (Cookies.get(&#8216;twitter_uid&#8217;) != undefined &#038;&#038; Cookies.get(&#8216;screen_name&#8217;) != undefined){<br \/>\n      history.push(&#8220;\/counter&#8221;)<br \/>\n    }<br \/>\n    else{<br \/>\n      alert(&#8220;\u8a8d\u8a3c\u306b\u5931\u6557\u3057\u307e\u3057\u305f&#8221;)<br \/>\n    }<br \/>\n  }<br \/>\n  else{<br \/>\n    setTimeout(function(){CheckLoginStatusTwitter(history)}, 1000)<br \/>\n  }<br \/>\n}<\/p>\n<p>[\/bash]<br \/>\n<a href=\"http:\/\/lovelinux.mydns.jp\/wp-content\/uploads\/2017\/04\/oauth-14.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/lovelinux.mydns.jp\/wp-content\/uploads\/2017\/04\/oauth-14.png\" alt=\"oauth-14\" width=\"812\" height=\"305\" class=\"alignnone size-full wp-image-1625\" \/><\/a><\/p>\n<h3>\u3042\u3068\u304c\u304d<\/h3>\n<p>\u3042\u3063\u3055\u308a\u3068\u8aac\u660e\u3057\u3061\u3083\u3044\u307e\u3057\u305f\u304c\u3001\u7406\u5c48\u304c\u308f\u304b\u308b\u307e\u3067\u3082\u5c11\u3057\u6642\u9593\u304c\u304b\u304b\u308a\u307e\u3057\u305f\u3002<br \/>\nSPA\u3067SNS\u8a8d\u8a3c\u3059\u308b\u306a\u3089\u3069\u3046\u3059\u308a\u3083\u3044\u3044\u3093\u3060\u3068\u3044\u3046\u60c5\u5831\u304c\u3001\u4ee5\u5916\u306b\u306a\u304f\u3066\u30fb\u30fb\u30fb<br \/>\n\u3042\u3061\u3053\u3061\u8aad\u307f\u6f01\u3063\u3066\u3001\u306a\u3093\u3068\u304b\u5f62\u306b\u306a\u308a\u307e\u3057\u305f\u3002<br \/>\n\u4f55\u304b\u306e\u53c2\u8003\u306b\u306a\u308c\u3070\u3068\u30fb\u30fb\u30fb\u30fb<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u306f\u3058\u3081\u306b React\u3067SPA\u3092\u4f5c\u308b\u3053\u3068\u306b\u306a\u3063\u3066\u3001\u30ed\u30b0\u30a4\u30f3\u8a8d\u8a3c\u306b\u30e1\u30fc\u30eb\uff06\u30d1\u30b9\u30ef\u30fc\u30c9\u306e\u8a8d\u8a3c\u306b\u52a0\u3048\u3066\u3001 Google\u3084Twitter\u8a8d\u8a3c\u3082\u52a0\u3048\u305f\u304f\u306a\u3063\u305f\u6642\u3001\u3069\u3046\u3059\u308c\u3070\u3088\u3044\u304b\u308f\u304b\u3089\u306a\u304b\u3063\u305f\u3002 \u30d0\u30c3\u30af\u30a8\u30f3\u30c9\u306fRails\u3060\u304c\u3001\u3042\u304f\u307e\u3067API\u30b5\u30fc\u30d0\u30fc\u7684\u306a\u7acb\u5834\u306a\u306e\u3067 \u30e1\u30b8\u30e3\u30fc\u306aomniauth \u306a\u3093\u304b\u306f\u4f7f\u3048\u305d\u3046\u306b\u306a\u3044\u3002\u3002\u3002 \u524d\u56de\u306eGoogle\u7de8\u306b\u7d9a\u304d\u3001\u4eca\u56de\u306fTwitter\u7de8\u3002 \u3042\u308c\u3053\u308c\u60a9\u307f\u306a\u304c\u3089\u306a\u3093\u3068\u304b\u52d5\u304f\u3068\u3053\u308d\u307e\u3067\u305f\u3069\u308a\u7740\u3044\u305f\u306e\u3067\u3001\u3084\u308a\u65b9\u3092\u516c\u958b\u3002 React+Redux\u306e\u74b0\u5883\u306a\u3093\u3067\u3059\u304c\u3001\u305d\u3053\u307e\u3067\u7acb\u3061\u5165\u308b\u3068\u8a71\u304c\u3084\u3084\u3053\u3057\u304f\u306a\u308b\u306e\u3067\u3001 \u5b9f\u88c5\u306e\u30a8\u30ad\u30b9\u90e8\u5206\u3060\u3051\u3092\u8a18\u8f09\u3057\u3066\u307f\u307e\u3059\u3002 Twitter Developer\u306b\u30a2\u30d7\u30ea\u767b\u9332 Twitter Developer \u3053\u308c\u306b\u3064\u3044\u3066\u306f\u4e0a\u8a18\u306eURL\u306b\u30a2\u30af\u30bb\u30b9\u3057\u3066\u30a2\u30d7\u30ea\u3092\u767b\u9332\u3057\u3066\u304f\u3060\u3055\u3044\u3002 \u30a2\u30d7\u30ea\u540d\u3068\u30b3\u30fc\u30eb\u30d0\u30c3\u30afURL\u3092\u767b\u9332\u3057\u305f\u3089\u3001Consumer Key (API Key)\u3068Consumer Secret (API Secret)\u304c\u3082\u3089\u3048\u307e\u3059\u3002 \u8a73\u3057\u304f\u306f\u66f8\u304d\u307e\u305b\u3093\u3001\u30b0\u30b0\u308c\u3070\u3053\u308c\u306f\u305f\u304f\u3055\u3093\u66f8\u3044\u3066\u3042\u308a\u307e\u3059\u3002 \u52d5\u4f5c\u30a4\u30e1\u30fc\u30b8 \u30c7\u30b6\u30a4\u30f3\u306f\u3057\u3087\u307c\u3044\u3067\u3059\u304c\u3001\u3053\u3093\u306a\u611f\u3058\u306e\u30ed\u30b0\u30a4\u30f3\u753b\u9762\u3002 Google\u304bTwitter\u3067\u8a8d\u8a3c\u3057\u3066\u30ed\u30b0\u30a4\u30f3\u3057\u3066\u306d\u3001\u3068\u3044\u3046\u3082\u306e\u3002 \u4eca\u56de\u306fTwitter\u306b\u3064\u3044\u3066\u306e\u307f\u53d6\u308a\u4e0a\u3052\u307e\u3059\u3002 Twitter\u3067\u30ed\u30b0\u30a4\u30f3\u3092\u30af\u30ea\u30c3\u30af\u3059\u308b\u3068\u3001Twitter\u304c\u7528\u610f\u3057\u3066\u3044\u308bOAuth\u7528\u306e\u753b\u9762\u304c\u8868\u793a\u3055\u308c\u3066\u3001 Twitter\u306e\u30e6\u30fc\u30b6\u30fc\u540d\u3068\u30d1\u30b9\u30ef\u30fc\u30c9\u3092\u5165\u308c\u3066\u3001\u6700\u5f8c\u306b\u4eca\u56de\u4f5c\u308b\u30a2\u30d7\u30ea\uff08SPA\uff09\u3078\u306e\u30a2\u30af\u30bb\u30b9\u8a31\u53ef\u753b\u9762\u304c\u8868\u793a\u3055\u308c\u3001 \u8a31\u53ef\u3059\u308b\u3068\u3001SPA\u30a2\u30d7\u30ea\u306b\u30ed\u30b0\u30a4\u30f3\u51fa\u6765\u308b\u3068\u3044\u3046\u3082\u306e\u3002 \u30b9\u30c6\u30c3\u30d7\uff11(Javascript\u3001Ajax) \u307e\u305a\u306f \u307e\u305a\u306fTwitter\u306eOAuth\u7528URL\u306e\u53d6\u5f97\u306e\u305f\u3081\u306eRails API\uff08\u81ea\u4f5c\uff09\u547c\u3073\u51fa\u3057\u3002 React\u306e\u66f8\u304d\u65b9\u306a\u306e\u3067\u3001function\u3089\u3057\u304f\u306a\u3044\u3067\u3059\u304c\u30fb\u30fb\u30fb\u305f\u3060\u306efunction\u3060\u3068\u601d\u3063\u3066\u30bd\u30fc\u30b9\u3092\u898b\u3066\u304f\u3060\u3055\u3044\u3002 API\u547c\u3073\u51fa\u3057\u306e\u7d50\u679c\u3001OAuth\u7528\u306eURL\u304c\u5f97\u3089\u308c\u308b\u306e\u3067\u3001window.open\u3059\u308b\u611f\u3058\u3067\u3059\u3002 \u30dd\u30c3\u30d7\u30a2\u30c3\u30d7\u3068\u3044\u3046\u304b\u5225\u30bf\u30d6\u3067Twitter\u306eOAuth\u753b\u9762\u304c\u958b\u304d\u307e\u3059\u3002 \u3067\u3001window.open\u3057\u305f\u3042\u3068\u306f setTimeout\u30671\u79d2\u304a\u304d\u306b\u30a6\u30a3\u30f3\u30c9\u30a6\u304c\u9589\u3058\u305f\u304b\u3069\u3046\u304b\u3092\u30c1\u30a7\u30c3\u30af\u3057\u307e\u3059\u3002 [bash] onLoginTwitter: (history) => { axios.get(&#8220;http:\/\/localhost:3000\/get_twitter_oauth_url&#8221;, { withCredentials: true, params: {} }) .then(function (response) { windowLogin = window.open(response.data.oauth_url) setTimeout(function(){CheckLoginStatusTwitter(history)}, 1000) windowLogin.focus() }) .catch(function (response) { console.log(response); }); } [\/bash] \u30b9\u30c6\u30c3\u30d7\uff11\uff0e\uff15(Rails) \u30b9\u30c6\u30c3\u30d7\uff11\u304b\u3089\u547c\u3073\u51fa\u3055\u308c\u308bRails\u306e\u30bd\u30fc\u30b9\u3002 CONSUMER_ID\u3068CONSUMER_SECRET\u3092\u7528\u3044\u3066\u3001OAuth\u7528\u306eURL\u3092\u53d6\u5f97\u3057\u3001JSON\u3067\u7d50\u679c\u3092\u623b\u3057\u307e\u3059\u3002 [bash] require &#8216;oauth&#8217; def get_twitter_oauth_url consumer = OAuth::Consumer.new( Oauth::TWITTER_CONSUMER_ID, Oauth::TWITTER_CONSUMER_SECRET, { :site => &#8220;https:\/\/api.twitter.com&#8221; } ) request_token = consumer.get_request_token( :oauth_callback => &#8220;http:\/\/localhost:3000\/oauth_twitter&#8221; ) cookies[:request_token] = request_token.token cookies[:request_token_secret] = request_token.secret rtn = {} rtn[&#8220;status&#8221;] = true rtn[&#8220;oauth_url&#8221;] = request_token.authorize_url render json: rtn end [\/bash] \u30b9\u30c6\u30c3\u30d7\uff12(Javascript) \u30b9\u30c6\u30c3\u30d7\uff11\u306e\u30bd\u30fc\u30b9\u306eWindow\u547c\u3073\u51fa\u3057\u306e\u3068\u3053\u308d\u3060\u3051\u3092\u629c\u7c8b\u3002 Rails\u306eAPI\u3067\u623b\u3063\u3066\u304d\u305f\u8a8d\u8a3c\u7528URL\u3092\u5f15\u6570\u306b\u3057\u3066 window.open\u3002 [bash] windowLogin = window.open(response.data.oauth_url) [\/bash] \u30b9\u30c6\u30c3\u30d7\uff13 \u3053\u3053\u306f\u30d7\u30ed\u30b0\u30e9\u30e0\u3059\u308b\u5fc5\u8981\u306a\u3057\u3067\u3059\u3002Twitter\u306eOAuth\u306e\u753b\u9762\u3067 \u7d14\u7c8b\u306b\u8a8d\u8a3c\uff06\u8a31\u53ef\u3092\u3057\u3066\u3082\u3089\u3044\u307e\u3059\u3002 \u30b9\u30c6\u30c3\u30d7\uff14(Rails) Twitter\u5074\u306e\u8a8d\u8a3c\u3068\u8a31\u53ef\u306e\u51e6\u7406\u304c\u7d42\u308f\u308b\u3068\u3001\u30b9\u30c6\u30c3\u30d7\uff11\uff0e\uff15\u3067\u6307\u5b9a\u3057\u305f\u30b3\u30fc\u30eb\u30d0\u30c3\u30afURL\u306b\u5236\u5fa1\u304c\u623b\u3063\u3066\u304d\u307e\u3059\u3002 \u30c6\u30b9\u30c8\u74b0\u5883\u3067\u3059\u306e\u3067Rails\u306e\u30c7\u30d5\u30a9\u30eb\u30c8 http:\/\/localhost:3000 \u3067\u30b5\u30fc\u30d0\u30fc\u304c\u7acb\u3061\u4e0a\u304c\u3063\u3066\u3044\u3066\u3001 \u30b3\u30fc\u30eb\u30d0\u30c3\u30afURL\u306f\u3000http:\/\/localhost:3000\/oauth_twitter\u3000\u3067\u3059\u3002 \u3067\u306f\u3001Rails\u306e\u65b9\u306e\u5b9f\u88c5\u3092\u898b\u3066\u307f\u307e\u3057\u3087\u3046\u3002 \u6700\u521d\u306bCONSUMER_ID\u3068CONSUMER_SECRET\u3092\u7528\u3044\u3066\u3001\u30c8\u30fc\u30af\u30f3\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002 \u3055\u3089\u306b\u3001\u30d1\u30e9\u30e1\u30fc\u30bf\u30fc\u3067\u6e21\u3063\u3066\u304d\u305f\u3001 oauth_token\u3068oauth_verifier\u3092\u4f7f\u3063\u3066 \u30a2\u30af\u30bb\u30b9\u30c8\u30fc\u30af\u30f3\u3092\u5f97\u307e\u3059\u3002 \u6700\u5f8c\u306b\u5f97\u3089\u308c\u305f\u30a2\u30af\u30bb\u30b9\u30c8\u30fc\u30af\u30f3\u3092\u4f7f\u3063\u3066API\u30a2\u30af\u30bb\u30b9\u3057\u3001\u30e6\u30fc\u30b6\u30fc\u60c5\u5831\u3092\u5f97\u307e\u3059\u3002 \u3067\u3001cookies\u306b\u5f97\u3089\u308c\u305f\u60c5\u5831\u3092\u30bb\u30c3\u30c8\u3057\u3066\u3001\u3053\u306e\u30e1\u30bd\u30c3\u30c9\u3092\u629c\u3051\u307e\u3059\u3002 cookies[:oauth_token] = params[:oauth_token] cookies[:twitter_uid] = user_info[&#8220;id&#8221;] cookies[:screen_name] = user_info[&#8220;screen_name&#8221;] [bash] class OauthController < ApplicationController #URL \/oauth_twitter \u3078\u306e\u51e6\u7406 def twitter consumer = OAuth::Consumer.new( Oauth::TWITTER_CONSUMER_ID, Oauth::TWITTER_CONSUMER_SECRET, { :site => &#8220;https:\/\/api.twitter.com&#8221; } ) request_token = OAuth::RequestToken.new( consumer, cookies[:request_token], cookies[:request_token_secret] ) access_token = request_token.get_access_token( {}, :oauth_token => params[:oauth_token], :oauth_verifier => params[:oauth_verifier] ) response = consumer.request( :get, &#8216;\/1.1\/account\/verify_credentials.json&#8217;, access_token, { :scheme => :query_string } ) rtn = {} case response when Net::HTTPSuccess user_info = JSON.parse(response.body) if user_info[&#8220;screen_name&#8221;] cookies[:oauth_token] = params[:oauth_token] cookies[:twitter_uid] = user_info[&#8220;id&#8221;] cookies[:screen_name] = user_info[&#8220;screen_name&#8221;] else #&#8221;Authentication failed&#8221; end else #&#8221;Failed to get user info via OAuth&#8221; end end end [\/bash] Rails\u306eGemfile\u306b\u4ee5\u4e0b\u306e\uff13\u3064\u306egem\u3092\u8ffd\u52a0\u3057\u307e\u3059\u3002 [bash] gem &#8216;json&#8217; gem &#8216;oauth&#8217; gem &#8216;rack-cors&#8217;, :require => &#8216;rack\/cors&#8217; [\/bash] SPA\u3092\u30b5\u30fc\u30d6\u3057\u3066\u3044\u308b\u30b5\u30fc\u30d0\u30fc\u3068API\u3092\u30b5\u30fc\u30d6\u3057\u3066\u3044\u308b\u30b5\u30fc\u30d0\u30fc\u304c\u5225\u7269\u306b\u306a\u308b\u306e\u3067\u3001 \u30af\u30ed\u30b9\u30c9\u30e1\u30a4\u30f3\u306aAPI\u30a2\u30af\u30bb\u30b9\u3068\u306a\u308b\u305f\u3081\u3001API\u5074\u3067\u305d\u308c\u3092\u8a31\u53ef\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002 gem rack-cors \u3067\u305d\u308c\u306b\u5bfe\u5fdc\u3067\u304d\u307e\u3059\u3002\u3067\u3001\u5bfe\u5fdc\u3059\u308b\u305f\u3081\u306bapplication.rb\u3092 \u4ee5\u4e0b\u306e\u3088\u3046\u306b\u66f8\u304d\u63db\u3048\u307e\u3059\u3002\u3000\u672c\u756a\u3067\u306forigins\u306f\u300c\uff0a\u300d\u3067\u306f\u306a\u304f\u3001\u3061\u3083\u3093\u3068\u7279\u5b9a\u306e\u30c9\u30e1\u30a4\u30f3\u540d\u3092\u5165\u308c\u308b\u3079\u3057\u3002 config\/application.rb [bash] class Application < Rails::Application config.middleware.insert_before ActionDispatch::Static, Rack::Cors do allow do origins '*' resource '*', :headers => :any, :methods => [:get, :post, :delete] end end end [\/bash] \u30b9\u30c6\u30c3\u30d7\uff15(Rails\u306eJavascript) OauthController\u306etwitter\u30e1\u30bd\u30c3\u30c9\u3067\u51e6\u7406\u3092\u3057\u305f\u306e\u3067\u3001\u666e\u901a\u306b\u51e6\u7406\u304c\u7d42\u308f\u308c\u3070\u3001\u30dd\u30c3\u30d7\u30a2\u30c3\u30d7\u753b\u9762\u306b\u306f \u305d\u306e\u30e1\u30bd\u30c3\u30c9\u306b\u5bfe\u5fdc\u3059\u308b\u30d3\u30e5\u30fc\u304c\u8868\u793a\u3055\u308c\u307e\u3059\u3002 \u306a\u306e\u3067\u3001\u5bfe\u5fdc\u3059\u308b\u30d3\u30e5\u30fc\u306f\u4f5c\u308b\u306e\u3067\u3059\u304c\u3001\u3042\u304f\u307e\u3067\u30c0\u30df\u30fc\u3067\u7d50\u69cb\u3067\u3059\u3002 \u305d\u3082\u305d\u3082\u3001\u30dd\u30c3\u30d7\u30a2\u30c3\u30d7\uff08\u5225\u30bf\u30d6\uff09\u3067Twitter\u8a8d\u8a3c\u304c\u958b\u3044\u3066\u3044\u3066\u3001\u8a8d\u8a3c\u304c\u7d42\u308f\u308c\u3070\u30dd\u30c3\u30d7\u30a2\u30c3\u30d7\u306f\u9589\u3058\u3066\u307b\u3057\u3044 \u306f\u305a\u3067\u3059\u306e\u3067\u30fb\u30fb\u30fb \u3067\u3001assets\/javascripts \u914d\u4e0b\u306b\u4ee5\u4e0b\u306e\u3088\u3046\u306aJavaScript\uff08CoffeeScript\u3067\u306f\u306a\u3044\uff09\u3092\u4f5c\u308a\u307e\u3059\u3002 \u30d5\u30a1\u30a4\u30eb\u540d\u306f\u306a\u3093\u3067\u3082\u3044\u3044\u3002 \u3067\u3001\u3053\u3053\u3067\u3059\u308b\u51e6\u7406\u306f\u3001\u30c0\u30df\u30fc\u306e\u30d3\u30e5\u30fc\u304c\u8868\u793a\u3055\u308c\u305f\u6642\u306b\u305d\u306ehref\u3092\u30c1\u30a7\u30c3\u30af\u3057\u3066\u3001 \u8a8d\u8a3c\u7d42\u4e86\u306e\u30c0\u30df\u30fc\u30d3\u30e5\u30fc\u3060\u3068\u5224\u5b9a\u3067\u304d\u305f\u3089\u3001window.close\u3057\u3066\u3084\u308b\u3068\u3044\u3046\u3082\u306e\u3067\u3059\u3002 [bash] $(function(){ if (window.location.href.indexOf(&#8220;oauth_twitter&#8221;) >0){ window.close(); }&#8230;<\/p>\n","protected":false},"author":1,"featured_media":1620,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_uf_show_specific_survey":0,"_uf_disable_surveys":false,"footnotes":""},"categories":[6,77],"tags":[80,71,72,81],"class_list":{"0":"post-1619","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-rails","8":"category-react","9":"tag-oauth","10":"tag-rails","11":"tag-reactjs","12":"tag-twitter"},"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/lovelinux.mydns.jp\/index.php?rest_route=\/wp\/v2\/posts\/1619","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lovelinux.mydns.jp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lovelinux.mydns.jp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lovelinux.mydns.jp\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lovelinux.mydns.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1619"}],"version-history":[{"count":5,"href":"https:\/\/lovelinux.mydns.jp\/index.php?rest_route=\/wp\/v2\/posts\/1619\/revisions"}],"predecessor-version":[{"id":1631,"href":"https:\/\/lovelinux.mydns.jp\/index.php?rest_route=\/wp\/v2\/posts\/1619\/revisions\/1631"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lovelinux.mydns.jp\/index.php?rest_route=\/wp\/v2\/media\/1620"}],"wp:attachment":[{"href":"https:\/\/lovelinux.mydns.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1619"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lovelinux.mydns.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1619"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lovelinux.mydns.jp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1619"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}