<?xml version="1.0" encoding="UTF-8"?>
<page xmlns="http://api.springnote.com">
  <identifier type="integer">475676</identifier>
  <title> Ruby On Rails, OpenId &#47196; &#47196;&#44536;&#51064; &#44592;&#45733; &#44396;&#54788; </title>
  <relation_is_part_of type="integer">335493</relation_is_part_of>
  <date_modified type="datetime">2007-09-15T10:52:48Z</date_modified>
  <uri>http://shinji.springnote.com/pages/475676</uri>
  <date_created type="datetime">2007-09-15T10:52:12Z</date_created>
  <source>&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h4&gt;&#50724;&#54536; &#50500;&#51060;&#46356;&#47196; &#47196;&#44536;&#51064; &#44592;&#45733; &#44396;&#54788;&lt;/h4&gt;
&lt;p&gt;&lt;a href="http://agilewebdevelopment.com/plugins/openidauthentication" class="con_link" target="_blank"&gt;&#52280;&#44256;&#47928;&#49436;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Plugins - Open Id Authentication &#46972;&#45716; &#54540;&#47084;&#44536;&#51064;&#51004;&#47196; &#49789;&#44172; &#44396;&#54788;&#54624; &#49688; &#51080;&#45796;.&lt;/p&gt;
&lt;p&gt;&#50864;&#49440;&#51008; ruby-openid &#47484; &#47676;&#51200; &#49444;&#52824;&#54644;&#50556;&#54620;&#45796;.&lt;/p&gt;
&lt;pre&gt;
&lt;code&gt;gem install ruby-openid&lt;br /&gt;&lt;/code&gt;
&lt;/pre&gt;
&lt;p&gt;&#47196; &#49444;&#52824;.&lt;/p&gt;
&lt;p&gt;&#49444;&#52824; &#54616;&#44256; &#54540;&#47084;&#44536;&#51064;&#51012; &#49444;&#52824;&#54620;&#45796;.&lt;/p&gt;
&lt;pre&gt;
&lt;code&gt;ruby script/plugin install http://svn.rubyonrails.org/rails/plugins/open_id_authentication/&lt;br /&gt;&lt;/code&gt;
&lt;/pre&gt;
&lt;p&gt;app/controllers/session_controller.rb &#51012; &#45796;&#51020;&#44284; &#44057;&#51060; &#47564;&#46304;&#45796;.&lt;/p&gt;
&lt;pre&gt;
&lt;code&gt;  class SessionController &amp;lt; ApplicationController&lt;br /&gt;
    def create&lt;br /&gt;
      if open_id?(params[:name])&lt;br /&gt;
        open_id_authentication(params[:name])&lt;br /&gt;
      else&lt;br /&gt;
        password_authentication(params[:name], params[:password])&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    protected&lt;br /&gt;
      def password_authentication(name, password)&lt;br /&gt;
        if @current_user = @account.users.find_by_name_and_password(params[:name], params[:password])&lt;br /&gt;
          successful_login&lt;br /&gt;
        else&lt;br /&gt;
          failed_login "Sorry, that username/password doesn't work"&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      def open_id_authentication(identity_url)&lt;br /&gt;
        authenticate_with_open_id(identity_url) do |status, identity_url|&lt;br /&gt;
          case status&lt;br /&gt;
          when :missing&lt;br /&gt;
            failed_login "Sorry, the OpenID server couldn't be found"&lt;br /&gt;
          when :canceled&lt;br /&gt;
            failed_login "OpenID verification was canceled"&lt;br /&gt;
          when :failed&lt;br /&gt;
            failed_login "Sorry, the OpenID verification failed"&lt;br /&gt;
          when :successful&lt;br /&gt;
            if @current_user = @account.users.find_by_identity_url(identity_url)&lt;br /&gt;
              successful_login&lt;br /&gt;
            else&lt;br /&gt;
              failed_login "Sorry, no user by that identity URL exists"&lt;br /&gt;
            end&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
    private&lt;br /&gt;
      def successful_login&lt;br /&gt;
        session[:user_id] = @current_user.id&lt;br /&gt;
        redirect_to(root_url)&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      def failed_login(message)&lt;br /&gt;
        flash[:error] = message&lt;br /&gt;
        redirect_to(new_session_url)&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      # Set #root_url if your root url has a different named route.&lt;br /&gt;
      #&lt;br /&gt;
      #   map.home '', :controller =&amp;gt; ..., :action =&amp;gt; ...&lt;br /&gt;
      #&lt;br /&gt;
      # Otherwise, name the route 'root' and leave this method out.&lt;br /&gt;
      def root_url&lt;br /&gt;
        home_url&lt;br /&gt;
      end&lt;br /&gt;
  end&lt;br /&gt;&lt;/code&gt;
&lt;/pre&gt;
&lt;h5&gt;Opend ID &#47484; &#51060;&#50857;&#54620; &#44036;&#45800;&#54620; &#46321;&#47197; &#48169;&#48277;.&lt;/h5&gt;
&lt;p&gt;OpenId &#54532;&#47196;&#54596; &#44368;&#54872; &#54532;&#47196;&#53664;&#53084;&#51008; &#45796;&#51020;&#51012; &#52280;&#44256;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.openidenabled.com/openid/simple-registration-extension" class="con_link" target="_blank"&gt;http://www.openidenabled.com/openid/simple-registration-extension&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&#50948;&#50640;&#49436; open_id_authentication &#51012; &#45796;&#51020;&#44284; &#44057;&#51060; &#48148;&#45000;&#51004;&#47196;&#49436; &#54644;&#44208;&#46108;&#45796;.&lt;/p&gt;
&lt;pre&gt;
&lt;code&gt;  def open_id_authentication(identity_url)&lt;br /&gt;
    # Pass optional :required and :optional keys to specify what sreg fields you want.&lt;br /&gt;
    # Be sure to yield registration, a third argument in the #authenticate_with_open_id block.&lt;br /&gt;
    authenticate_with_open_id(identity_url, :required =&amp;gt; [:nickname, :email], :optional =&amp;gt; :fullname) do |status, identity_url, registration|&lt;br /&gt;
      case status&lt;br /&gt;
      when :missing&lt;br /&gt;
        failed_login "Sorry, the OpenID server couldn't be found"&lt;br /&gt;
      when :canceled&lt;br /&gt;
        failed_login "OpenID verification was canceled"&lt;br /&gt;
      when :failed&lt;br /&gt;
        failed_login "Sorry, the OpenID verification failed"&lt;br /&gt;
      when :successful&lt;br /&gt;
        if @current_user = @account.users.find_by_identity_url(identity_url)&lt;br /&gt;
          # registration is a hash containing the valid sreg keys given above&lt;br /&gt;
          # use this to map them to fields of your user model&lt;br /&gt;
          {'login=' =&amp;gt; 'nickname', 'email=' =&amp;gt; 'email', 'display_name=' =&amp;gt; 'fullname'}.each do |attr, reg|&lt;br /&gt;
            current_user.send(attr, registration[reg]) unless registration[reg].blank?&lt;br /&gt;
          end&lt;br /&gt;
          unless current_user.save&lt;br /&gt;
            flash[:error] = "Error saving the fields from your OpenID profile: #{current_user.errors.full_messages.to_sentence}"&lt;br /&gt;
          end&lt;br /&gt;
          successful_login&lt;br /&gt;
        else&lt;br /&gt;
          failed_login "Sorry, no user by that identity URL exists"&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;&lt;/code&gt;
&lt;/pre&gt;
&lt;p&gt;&#54540;&#47084;&#44536;&#51064; &#51200;&#51109;&#49548;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://svn.rubyonrails.org/rails/plugins/open_id_authentication/" class="con_link" target="_blank"&gt;http://svn.rubyonrails.org/rails/plugins/open_id_authentication/&lt;/a&gt;&lt;/p&gt;
</source>
  <rights nil="true"></rights>
  <creator>http://shinji.idpia.com/</creator>
  <contributor_modified>http://shinji.idpia.com/</contributor_modified>
  <version type="integer">2</version>
  <tags></tags>
</page>
