ããã¿ããªOpenIDã«ã
はてなもようやくOpenID providerになったã¨ãããã¨ã§ã試ãã¦ã¿ããã ãã©ããã¯ããã
ï¼ããããä»çµã¿ãªãã ããå½ããåã ãã©ï¼OpenIDã§èªè¨¼å¶å¾¡ãããããã«å®è£
ããããã°å¾ã¯è§¦ããã¨ããè¤æ°ã®èªè¨¼ãµã¼ãã¹ã«å¯¾å¿ã§ãããæ°ãã«OpenID providerãç¾ãã¦ãä½ãããªãã¦ãããããã«ããã使ã£ã¦èªè¨¼ãéãã
èªè¨¼APIã«ä½µãã¦ãã¡ãã¡gemãå
¥ãããããªãã¦ãããããã°ã¤ã³ãªã³ã¯ããã£ãããMNã¯TypeKeyã¨ã¯ã¦ãªèªè¨¼ã®ä½µç¨ãæçç«ã¯ã¯ã¦ãªèªè¨¼ã¨livedoor Authã®ä½µç¨ã ããããµã¤ããã¼ã«ã¯äºã¤ã®ãã°ã¤ã³ãªã³ã¯ãåºã¦ãããããOpenIDãªãã°URLãå
¥ãããã©ã¼ã ä¸ã¤ããã°ããã
å®è£
ãç°¡åãããããã«ã
$ sudo gem install ruby-openid $ sudo gem install openid_login_generator $ ./script/generate openid_login openid
ç¶ãã¦ãMigrationå®ç¾©ãæ¸ãã¦usersãã¼ãã«ã«openid_url(string)ã¨ããã«ã©ã ã追å ã
/opt/local/lib/ruby/gems/1.8/gems/ruby-openid-x.x.x/examples/active_record_openid_storeã«ãã©ã°ã¤ã³ãå
¥ã£ã¦ããã®ã§ãããvendor/pluginsã«ã³ãã¼ããapp/controller/openid_controller.rbã®ä¸ã®æ¹ãconsumerã¡ã½ãããæ¸ãæããã¨OpenID Storeã«ARã使ãããã«ãªã£ã¦ãã¡ã¤ã«ãçæãããªããªããã綺éºã
def consumer store = ActiveRecordOpenIDStore.new return OpenID::Consumer.new(session, store) end
ããã§OpenIDã«ããèªè¨¼ã使ããããã«ãªããhttp://localhost:3000/openid/loginãéãã¦ãã©ã¼ã ã«URLãå
¥ãã¦loginãæ¼ãã°ãå¤é¨èªè¨¼ã«é£ãã§å¸°ã£ã¦ãããsession[:user_id]ã«ã¦ã¼ã¶IDãå
¥ãã®ã§ãå¾ã¯ç
®ããªãç¼ããªãã
ä¿¡ç¨ããOpenIDãå¶éããã«ã¯ãloginã¢ã¯ã·ã§ã³ã§
request = consumer.begin(openid_url)
ãããåã«openid_urlãè¦ã¦å¶éãããã¾ãããã®ã¸ã§ãã¬ã¼ã¿ã§ä½ãããcontrollerã¯ã¡ãã£ã¨å¤ãã¿ããã§@sessionã ã®ãªãã ã®ä½¿ã£ã¦ããããç½®æãã¦è¦åãæ¶ãã¦ãããã