<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>cocoa*life</title>
	<atom:link href="http://www.cocoalife.net/feed" rel="self" type="application/rss+xml" />
	<link>http://www.cocoalife.net</link>
	<description>Whether we can achieve something entirely depends upon our intensity of faith.</description>
	<lastBuildDate>Wed, 09 May 2012 11:36:13 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Fade-in animation at UIView&#8217;s drawRect</title>
		<link>http://www.cocoalife.net/2012/05/post_892.html</link>
		<comments>http://www.cocoalife.net/2012/05/post_892.html#comments</comments>
		<pubDate>Wed, 09 May 2012 11:27:44 +0000</pubDate>
		<dc:creator>milkcocoa</dc:creator>
				<category><![CDATA[Cocoa]]></category>

		<guid isPermaLink="false">http://www.cocoalife.net/?p=892</guid>
		<description><![CDATA[Although UIView&#8217;s animateWithDuration:animations: method is quite useful, if you want a view to animate a drawing code written in drawRect method, you can&#8217;t use this method. CABasicAnimation class is suitable for solving this problem like this. Reference iphone &#8211; Redrawing a UIView with a fade animation? &#8211; Stack Overflow]]></description>
			<content:encoded><![CDATA[				<p>Although UIView&#8217;s animateWithDuration:animations: method is quite useful, if you want a view to animate a drawing code written in drawRect method, you can&#8217;t use this method.</p>
				<p>CABasicAnimation class is suitable for solving this problem like this.</p>
				<pre class="brush: objc; title: ; notranslate">- (void)drawRect:(CGRect)rect
{
    CABasicAnimation *animation;

    animation = [CABasicAnimation animation];
    [animation setDuration:0.5];

    [[self layer] addAnimation:animation
                        forKey:@&quot;contents&quot;];

    // drawing code
}</pre>
				<h2>Reference</h2>
				<ul>
				<li><a target="_blank" href="http://stackoverflow.com/questions/8567420/redrawing-a-uiview-with-a-fade-animation">iphone &#8211; Redrawing a UIView with a fade animation? &#8211; Stack Overflow</a></li>
				</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.cocoalife.net/2012/05/post_892.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>nginx Upload Progress Module with MacPorts</title>
		<link>http://www.cocoalife.net/2012/03/post_888.html</link>
		<comments>http://www.cocoalife.net/2012/03/post_888.html#comments</comments>
		<pubDate>Tue, 20 Mar 2012 08:09:15 +0000</pubDate>
		<dc:creator>milkcocoa</dc:creator>
				<category><![CDATA[UN*X]]></category>

		<guid isPermaLink="false">http://www.cocoalife.net/?p=888</guid>
		<description><![CDATA[I needed use nginx Upload Progress Module to create a progress bar. HttpUploadProgressModule In local development, I use MacPorts to install nginx, but MacPorts does not have variant for that module. So, I edited Portfile which is suitable for it. I uploaded it to Gist. Then, I installed nginx with the following command. You can [...]]]></description>
			<content:encoded><![CDATA[				<p>I needed use nginx Upload Progress Module to create a progress bar.</p>
				<p><a target="_blank" href="http://wiki.nginx.org/HttpUploadProgressModule">HttpUploadProgressModule</a></p>
				<p>In local development, I use MacPorts to install nginx, but MacPorts does not have variant for that module.<br />
				So, I edited Portfile which is suitable for it.</p>
				<p>I uploaded it to <a target="_blank" href="https://gist.github.com/2096500">Gist</a>.</p>
				<p>Then, I installed nginx with the following command.</p>
				<pre class="brush: bash; title: ; notranslate">$ sudo port install nginx +ssl +uplaod_progress</pre>
<p>You can see &#8220;&#8211;add-module&#8221; directive in this command, if the module is installed properly.</p>
<pre class="brush: bash; title: ; notranslate">$ nginx -V</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.cocoalife.net/2012/03/post_888.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Upgrading VMWare vSphere Hypervisor (ESXi) 4.1 to 4.1 Update 1 through SSH</title>
		<link>http://www.cocoalife.net/2011/05/post_877.html</link>
		<comments>http://www.cocoalife.net/2011/05/post_877.html#comments</comments>
		<pubDate>Sun, 22 May 2011 10:24:23 +0000</pubDate>
		<dc:creator>milkcocoa</dc:creator>
				<category><![CDATA[UN*X]]></category>

		<guid isPermaLink="false">http://www.cocoalife.net/?p=877</guid>
		<description><![CDATA[I upgraded VMWare vSphere Hypervisor (ESXi) 4.1 to 4.1 Update 1 through ssh, and here&#8217;s the way. First, you must enable SSH by the console or vSphere Client. The following web page shows the detail process for it, but I have not set up the non-root user yet. ESXi (ESX 4i) Enable SSH After that, [...]]]></description>
			<content:encoded><![CDATA[				<p>I upgraded VMWare vSphere Hypervisor (ESXi) 4.1 to 4.1 Update 1 through ssh, and here&#8217;s the way.</p>
				<p>First, you must enable SSH by the console or vSphere Client. The following web page shows the detail process for it, but I have not set up the non-root user yet.</p>
				<p><a target="_blank" href="http://www.vm-help.com/esx40i/ESXi_enable_SSH.php">ESXi (ESX 4i) Enable SSH</a></p>
				<p>After that, you can login as root user (if you&#8217;ve set up non-root user, use it).</p>
				<pre class="brush: bash; title: ; notranslate">$ ssh root@esxi-server-ip</pre>
<p>To enter the maintenance mode, shutdown all virtual machines. I don&#8217;t know the way of shutting down all at once, and execute the command many times.</p>
<pre class="brush: bash; title: ; notranslate"># vim-cmd vmsvc/power.shutdown &amp;lt;vmid&amp;gt;</pre>
				<p>You can use this command in order to know the vmid.</p>
				<pre class="brush: bash; title: ; notranslate"># vim-cmd vmsvc/getallvms</pre>
<p>Enter the maintenance mode.</p>
<pre class="brush: bash; title: ; notranslate"># vim-cmd hostsvc/maintenance_mode_enter</pre>
				<p>Download the update file (update-from-esxi4.1-4.1_update01.zip), and send it by SCP. Since ESXi server, however, doesn&#8217;t have &#8216;unzip&#8217; program, I unzipped the files on my Mac and send the directory.</p>
				<pre class="brush: bash; title: ; notranslate">$ scp -r update-from-esxi4 root@esxi-server-ip:/vmfs/volumes/Your-Data-Storage-Name</pre>
<p>You can check the data storage name by the command `ls /vmfs/volumes/`.</p>
<p>The preparation step is done, and go!</p>
<pre class="brush: bash; title: ; notranslate"># cd /vmfs/volumes/Your-Data-Storage-Name/update-from-esxi4
# esxupdate update -m metadata.zip</pre>
				<p>After updated, you must exit maintenance mode and reboot the machine.</p>
				<pre class="brush: bash; title: ; notranslate"># vim-cmd hostsvc/maintenance_mode_exit
# reboot</pre>
				<p>Finally, you can check the current version of Hypervisor by the following command.</p>
				<pre class="brush: bash; title: ; notranslate"># vmware -v
VMware ESXi 4.1.0 build-348481</pre>
				<h2>References</h2>
				<ul>
				<li><a target="_blank" href="http://www.vm-help.com/esx40i/ESXi_enable_SSH.php">ESXi (ESX 4i) Enable SSH</a></li>
				<li><a target="_blank" href="http://hoge2rock.com/401/">ESXiにSSHでログインしてよく使うコマンド | ホゲホゲロック</a> (in Japanese)</li>
				<li><a target="_blank" href="http://www.masatom.in/pukiwiki/VMware/ESXi/VMware%20Infrastructure%20Remote%20CLI%A4%F2%CD%F8%CD%D1%A4%B9%A4%EB/">VMware/ESXi/VMware Infrastructure Remote CLIを利用する &#8211; きのさいと</a> (in Japanese)</li>
				<li><a target="_blank" href="http://akitosblog.seesaa.net/article/199943980.html">[VMware] VMware ESXiを4.0.0から4.1.0へアップデートする方法: Akito&#8217;s IT技術 メモ</a> (in Japanese)</li>
				<li><a target="_blank" href="http://ehsia.com/scp-to-esxi-in-mac-os-x/">ehsia.com – my stuff and reviews » SCP to ESXi in Mac OS X</a></li>
				<li><a target="_blank" href="http://communities.vmware.com/message/1161616">VMware Communities: how to check esx version from command&#8230;</a></ul>
]]></content:encoded>
			<wfw:commentRss>http://www.cocoalife.net/2011/05/post_877.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Get current time in UTC, suitable for file name</title>
		<link>http://www.cocoalife.net/2011/04/post_871.html</link>
		<comments>http://www.cocoalife.net/2011/04/post_871.html#comments</comments>
		<pubDate>Tue, 12 Apr 2011 07:12:24 +0000</pubDate>
		<dc:creator>milkcocoa</dc:creator>
				<category><![CDATA[UN*X]]></category>

		<guid isPermaLink="false">http://www.cocoalife.net/?p=871</guid>
		<description><![CDATA[Using the following &#8216;date&#8217; command, we can get current time in UTC whose format is suitable for such as file name.]]></description>
			<content:encoded><![CDATA[				<p>Using the following &#8216;date&#8217; command, we can get current time in UTC whose format is suitable for such as file name.</p>
				<pre class="brush: bash; title: ; notranslate">$ date -u &quot;+%Y%m%d%H%M%S&quot;
$ 20110412065955</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.cocoalife.net/2011/04/post_871.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to use Xcode 3 color themes in Xcode 4</title>
		<link>http://www.cocoalife.net/2011/03/post_872.html</link>
		<comments>http://www.cocoalife.net/2011/03/post_872.html#comments</comments>
		<pubDate>Wed, 30 Mar 2011 11:55:55 +0000</pubDate>
		<dc:creator>milkcocoa</dc:creator>
				<category><![CDATA[Cocoa]]></category>

		<guid isPermaLink="false">http://www.cocoalife.net/?p=872</guid>
		<description><![CDATA[I&#8217;m using either MyBlackboard (In Japanese) or Railscasts color themes in Xcode 3, these color themes, however, couldn&#8217;t be used in Xcode 4. I want to convert 3&#8242;s xccolortheme files into 4&#8242;s dvtcolortheme files, and found the just script which converted it. mrevilme&#8217;s gist: 488120 — Gist The usage of this tiny python script is [...]]]></description>
			<content:encoded><![CDATA[				<p>I&#8217;m using either <a target="_blank" href="http://d.hatena.ne.jp/griffin-stewie/20090519/p1">MyBlackboard (In Japanese)</a> or <a target="_blank" href="http://blog.codefront.net/2010/02/04/railscasts-xcode-theme/">Railscasts</a> color themes in Xcode 3, these color themes, however, couldn&#8217;t be used in Xcode 4.</p>
				<p>I want to convert 3&#8242;s xccolortheme files into 4&#8242;s dvtcolortheme files, and found the just script which converted it.<br />
				<a target="_blank" href="https://gist.github.com/488120">mrevilme&#8217;s gist: 488120 — Gist</a></p>
				<p>The usage of this tiny python script is very simple like the following command.</p>
				<pre class="brush: bash; title: ; notranslate">$ xcode3_theme_to_xcode4.py MyBlackBoard.xcolortheme</pre>
<p>This step is very quick, and finally, I moved the dvtcolortheme file to the directory.</p>
<pre class="brush: bash; title: ; notranslate">mkdir -p ~/Library/Developer/Xcode/UserData/FontAndColorThemes/
mv MyBlackBoard.dvtcolortheme ~/Library/Developer/Xcode/UserData/FontAndColorThemes/</pre>
				<p>If you&#8217;ve already started Xcode, restart it and you&#8217;ll find the theme at the preference of Xcode.</p>
				<h2>References</h2>
				<ul>
				<li><a target="_blank" href="http://d.hatena.ne.jp/griffin-stewie/20090519/p1">Xcodeのテーマ（Color Theme） &#8211; griffin-stewieの日記</a></li>
				<li><a target="_blank" href="http://blog.codefront.net/2010/02/04/railscasts-xcode-theme/">Railscasts Xcode theme &#8211; redemption in a blog</a></li>
				<li><a target="_blank" href="https://gist.github.com/488120">mrevilme&#8217;s gist: 488120 — Gist</a></li>
				<li><a target="_blank" href="https://gist.github.com/524860">mrevilme&#8217;s gist: 524860 — Gist</a></li>
				</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.cocoalife.net/2011/03/post_872.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Plantronics Discovery 975 Bluetooth Headset の Tips</title>
		<link>http://www.cocoalife.net/2011/02/post_867.html</link>
		<comments>http://www.cocoalife.net/2011/02/post_867.html#comments</comments>
		<pubDate>Sun, 06 Feb 2011 06:01:57 +0000</pubDate>
		<dc:creator>milkcocoa</dc:creator>
				<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://www.cocoalife.net/?p=867</guid>
		<description><![CDATA[Plantronics Discovery 975 Bluetooth Headset という Bluetooth で使うヘッドセットを購入しました。 微妙にいくつかの点ではまったので、備忘録を残しておくことにします。 2010年のマニュアルは一部情報が削除されている。MyHeadset.jp &#124; Bluetooth イヤーピース Discovery 975で見られるマニュアルを参照する。 デフォルトではオフになっているマルチポイント接続機能をオンにしないと2台で使えない。 ペアリングは電源を切ってから。コントロールボタンを長押しすれば、赤白に点滅してペアリングモードに入れる。 Amazon.com で購入した方が安い。 ヘッドセットを購入したのはこれが初めてですが、普通のイヤホンであれば落ちてしまう自分の耳からも落ちずにクリアな音で使えるのがとてもいいと思いました。 参考文献 MyHeadset.jp &#124; Bluetooth イヤーピース Discovery 975 Bluetoothヘッドセット、Jabra BT8040からPlantronics Discovery 975に買い替えた: 遊手徒食 Plantronics Discovery 975マルチポイント設定 &#8211; jitsu102の日記]]></description>
			<content:encoded><![CDATA[				<p>Plantronics Discovery 975 Bluetooth Headset という Bluetooth で使うヘッドセットを購入しました。<br />
				<a href="http://www.cocoalife.net/wp-content/uploads/2011/02/0601.jpeg"><img src="http://www.cocoalife.net/wp-content/uploads/2011/02/0601.jpeg" alt="Plantronics Discovery 975 Bluetooth Headset" title="Plantronics Discovery 975 Bluetooth Headset" width="320" /></a></p>
				<p>微妙にいくつかの点ではまったので、備忘録を残しておくことにします。</p>
				<ul>
				<li>2010年のマニュアルは一部情報が削除されている。<a target="_blank" href="http://myheadset.jp/discovery975/">MyHeadset.jp | Bluetooth イヤーピース Discovery 975</a>で見られるマニュアルを参照する。</li>
				<li>デフォルトではオフになっているマルチポイント接続機能をオンにしないと2台で使えない。</li>
				<li>ペアリングは電源を切ってから。コントロールボタンを長押しすれば、赤白に点滅してペアリングモードに入れる。</li>
				<li><a target="_blank" href="http://www.amazon.com/dp/B002JIMZU4/">Amazon.com で購入</a>した方が安い。</li>
				</ul>
				<p>ヘッドセットを購入したのはこれが初めてですが、普通のイヤホンであれば落ちてしまう自分の耳からも落ちずにクリアな音で使えるのがとてもいいと思いました。</p>
				<h2>参考文献</h2>
				<ul>
				<li><a target="_blank" href="http://myheadset.jp/discovery975/">MyHeadset.jp | Bluetooth イヤーピース Discovery 975</a></li>
				<li><a target="_blank" href="http://aquila.cocolog-nifty.com/diary/2010/12/jabra-bt8040pla.html">Bluetoothヘッドセット、Jabra BT8040からPlantronics Discovery 975に買い替えた: 遊手徒食</a></li>
				<li><a target="_blank" href="http://d.hatena.ne.jp/jitsu102/20110105/1294227504">Plantronics Discovery 975マルチポイント設定 &#8211; jitsu102の日記</a></li>
				</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.cocoalife.net/2011/02/post_867.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to create OAuth / xAuth Service Provider in Ruby on Rails with devise</title>
		<link>http://www.cocoalife.net/2011/02/post_866.html</link>
		<comments>http://www.cocoalife.net/2011/02/post_866.html#comments</comments>
		<pubDate>Fri, 04 Feb 2011 03:56:35 +0000</pubDate>
		<dc:creator>milkcocoa</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://www.cocoalife.net/?p=866</guid>
		<description><![CDATA[At previous entiry I wrote a sample how to support xAuth in Ruby Application. In this entry, I write how to create the OAuth/xAuth Service Provider in Ruby on Rails project which uses devise plugin for authentication. OAuth support when you use devise plugin Installation First of all, I&#8217;m about to write the way of [...]]]></description>
			<content:encoded><![CDATA[				<p>At previous entiry I wrote a sample how to support xAuth in Ruby Application.</p>
				<p>In this entry, I write how to create the OAuth/xAuth Service Provider in Ruby on Rails project which uses devise plugin for authentication.</p>
				<h2>OAuth support when you use devise plugin</h2>
				<h3>Installation</h3>
				<p>First of all, I&#8217;m about to write the way of supporting OAuth using OAuth plugin.<br />
				<a target="_blank" href="https://github.com/pelle/oauth-plugin">pelle/oauth-plugin &#8211; GitHub</a></p>
				<p>OAuth plugin supports Rails 3 after version 0.4.0.pre1, and add Gemfile the following line.</p>
				<pre class="brush: ruby; title: ; notranslate">gem &quot;oauth-plugin&quot;, &quot;&gt;=0.4.0.pre1&quot;</pre>
<p>The installation tutorials are written in the github plugin page.</p>
<h3>devise plugin support</h3>
<p>In addition, to use OAuth plugin in the project which utilize devise, you need to support two methods &#8220;login_required&#8221; and &#8220;logged_in?&#8221; Devise uses such helper methods as &#8220;authenticate_#{model_name}&#8221; and &#8220;#{model_name}_signed_in?&#8221;, I wrote two helper methods.</p>
<p>[lib/lindoc/oauth_helpers.rb]</p>
<pre class="brush: ruby; title: ; notranslate">module Lindoc
  module OauthHelpers
    def self.included(recipient)
      recipient.extend(ClassMethods)
      recipient.class_eval do
        include InstanceMethods
      end
    end

    module InstanceMethods
      def login_required
        authenticate_user!
      end

      def logged_in?
        user_signed_in?
      end
    end
  end
end</pre>
				<p>At the controllers associated with OAuth, add this helper methods like the this.</p>
				<p>[$RAILS_ROOT/app/oauth_clients_controller.rb]</p>
				<pre class="brush: ruby; title: ; notranslate">class OauthClientsController &lt; ApplicationController
  include Lindoc::OauthHelpers
  ...
end</pre>
				<p>[$RAILS_ROOT/app/oauth_controller.rb]</p>
				<pre class="brush: ruby; title: ; notranslate">require 'oauth/controllers/provider_controller'

class OauthController &lt; ApplicationController
  include OAuth::Controllers::ProviderController
  include Lindoc::OauthHelpers
  ...
end</pre>
				<p>Since I want to use OAuth / xAuth authentication at API of our service, also added :oauth_required filter.</p>
				<p>[app/controllers/api/v1/api_controller.rb]</p>
				<pre class="brush: ruby; title: ; notranslate">class Api::V1::ApiController &lt; ApplicationController
  include Lindoc::OauthHelpers

  before_filter :oauth_required
  ...
end</pre>
				<h3>Rails nested parameters support</h3>
				<p>Client applications often post data in nested parameters like &#8220;foo[bar]=baz&#8221; to Rails application, but OAuth plugin doesn&#8217;t currently support this type of parameters. The reason why OAuth plugin doesn&#8217;t, is that this plugin doesn&#8217;t consider this type when it calculates a signature the way of which is written in the specification of OAuth, and answers a bad/invalid signature. So, you need to add support by overriding the method which helps calculate it.</p>
				<p>This solution is written at Issue page of OAuth plugin.<br />
				<a target="_blank" href="https://github.com/pelle/oauth/issues#issue/8">parameter normalisation issues Nesting parameters causes problems.</a></p>
				<p>[config/initializers/oauth.rb]</p>
				<pre class="brush: ruby; title: ; notranslate">module OAuth
  module Helper
    # see https://github.com/pelle/oauth/issues#issue/8
    def normalize(params)
      params.sort.map do |k, values|
        if values.is_a?(Array)
          # multiple values were provided for a single key
          values.sort.collect do |v|
            [escape(k),escape(v)] * &quot;=&quot;
          end
        elsif values.is_a?(Hash)
          key = k
          values.sort.collect do |k, v|
            [escape(&quot;#{key}[#{k}]&quot;),escape(v)] * &quot;=&quot;
          end
        else
          [escape(k),escape(values)] * &quot;=&quot;
        end
      end * &quot;&amp;&quot;
    end
  end
end]</pre>
				<h2>xAuth support</h2>
				<p>xAuth is the authentication method which is used in twitter to support desktop/mobile applications. If you want to know how to use xAuth in your applications, you should read <a target="_blank" href="http://dev.twitter.com/pages/xauth">this document</a>.<br />
				<a target="_blank" href="http://dev.twitter.com/pages/xauth">Using xAuth | dev.twitter.com</a></p>
				<h3>client application restriction</h3>
				<p>Like twitter, I want to restrict client applications which can use xAuth authentication, and I add column to decide it.</p>
				<p>[db/migrate/xxx_create_oauth_table.rb]</p>
				<pre class="brush: ruby; title: ; notranslate">class CreateOauthTables &lt; ActiveRecord::Migration
  def self.up
    create_table :client_applications do |t|
      ...
      t.boolean :xauth_enabled, :default =&gt; false

      t.timestamps
    end
    ...
  end
end</pre>
				<h3>/oauth/access_token signature verification method change</h3>
				<p>In OAuth 1.0 specification, service provider must verify a signature which consists of both Authentication header and GET or POST parameters called &#8220;Signature Base String&#8221;, and signed by both Consumer Secret and Access Token Secret. This verification step is implemented as filter &#8220;two_legged&#8221; or &#8220;oauth10_request_token&#8221; in OAuth plugin, OAuth::Controllers::ProviderController.</p>
				<p>[oauth-plugin/lib/oauth/controllers/provider_controller.rb]</p>
				<pre class="brush: ruby; title: ; notranslate">module OAuth
  module Controllers

    module ProviderController
      def self.included(controller)
        controller.class_eval do
          ...
          oauthenticate :strategies =&gt; :two_legged, :interactive =&gt; false, :only =&gt; [:request_token]
          oauthenticate :strategies =&gt; :oauth10_request_token, :interactive =&gt; false, :only =&gt; [:access_token]
          ...
</pre>
				<p>The simplified difference of these two methods is to use or not to use request token. You need to change signature verification method of /oauth/access_token when you request Access Token by xAuth, because unlike OAuth clients, xAuth clients don&#8217;t have request token.</p>
				<p>For that reason, to support xAuth, if request has &#8220;x_auth_mode=client_auth&#8221; in POST parametes which indicate client applications want to authenticate by xAuth, &#8220;two_legged&#8221; filter should be applied. I used &#8220;alias_method_chain&#8221; to seperate xAuth and OAuth authentication.</p>
				<p>[config/initializers/oauth.rb]</p>
				<pre class="brush: ruby; title: ; notranslate">module OAuth
  module Controllers
    module ApplicationControllerMethods
      class Authenticator
        def oauth10_request_token_with_xauth
          if params[:x_auth_mode] == 'client_auth'
            # xAuth authentication
            two_legged
          else
            # OAuth authentication
            oauth10_request_token_without_xauth
          end
        end

        alias_method_chain :oauth10_request_token, :xauth
      end
    end
  end
end</pre>
				<h3>/oauth/access_token user verification</h3>
				<p>In /oauth/access_token request, you also verify the user using his username and password. If there is a &#8220;x_auth_mode=client_auth&#8221; POST parameter in request, verify the user and response Access Token.</p>
				<p>[$RAILS_ROOT/app/oauth_controller.rb]</p>
				<pre class="brush: ruby; title: ; notranslate">require 'oauth/controllers/provider_controller'

class OauthController &lt; ApplicationController
  include OAuth::Controllers::ProviderController
  include Lindoc::OauthHelpers
  ....

  private
  def access_token_with_xauth
    # To use custom failure response with devise, you need the following line.
    # see https://github.com/plataformatec/devise/wiki/How-To:-Provide-a-custom-failure-response-with-Warden
    warden.custom_failure!

    if params[:x_auth_mode] == 'client_auth'
      render_unauthorized = Proc.new do
        render :nothing =&gt; true, :status =&gt; 401
      end

      # We support screen name and email to login
      user = User.find_for_database_authentication({ :screen_name_or_email =&gt; params[:x_auth_username] })
      if user &amp;&amp;
        user.valid_password?(params[:x_auth_password]) &amp;&amp;
        current_client_application.xauth_enabled

        @token = AccessToken.where(:user_id.eq =&gt; user,
                                   :client_application_id.eq =&gt; current_client_application,
                                   :invalidated_at.eq =&gt; nil).limit(1).first
        @token = AccessToken.create(:user =&gt; user, :client_application =&gt; current_client_application) if @token.blank?

        if @token
          render :text =&gt; @token.to_query
        else
          render_unauthorized.call
        end
      else
        render_unauthorized.call
      end
    else
      access_token_without_xauth
    end
  end

  alias_method_chain :access_token, :xauth
end</pre>
				<h2>References</h2>
				<ul>
				<li><a target="_blank" href="http://oauth.net/core/1.0/">OAuth Core 1.0</a></li>
				<li><a target="_blank" href="http://d.hatena.ne.jp/yuroyoro/20100506/1273137673">OAuthプロトコルの中身をざっくり解説してみるよ &#8211; ゆろよろ日記</a> (In Japanese)</li>
				<li><a target="_blank" href="https://github.com/oauth/oauth-ruby">oauth/oauth-ruby &#8211; GitHub</a></li>
				<li><a target="_blank" href="https://github.com/pelle/oauth-plugin">pelle/oauth-plugin &#8211; GitHub</a></li>
				<li><a target="_blank" href="https://github.com/pelle/oauth/issues#issue/8">parameter normalisation issues Nesting parameters causes problems.</a></li>
				<li><a target="_blank" href="https://github.com/igaiga/oauth_rails_sample">igaiga/oauth_rails_sample &#8211; GitHub</a></li>
				<li><a target="_blank" href="https://github.com/plataformatec/devise/wiki/How-To:-Provide-a-custom-failure-response-with-Warden">How To: Provide a custom failure response with Warden &#8211; GitHub</a></li>
				</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.cocoalife.net/2011/02/post_866.html/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>How to support OAuth in ASIHTTPRequest</title>
		<link>http://www.cocoalife.net/2011/01/post_865.html</link>
		<comments>http://www.cocoalife.net/2011/01/post_865.html#comments</comments>
		<pubDate>Mon, 24 Jan 2011 06:14:33 +0000</pubDate>
		<dc:creator>milkcocoa</dc:creator>
				<category><![CDATA[Cocoa]]></category>

		<guid isPermaLink="false">http://www.cocoalife.net/?p=865</guid>
		<description><![CDATA[ASIHTTPRequest is a brilliant library, when you want to handle HTTP requests. At this time, however, this library doesn&#8217;t support OAuth. You can support it easily with OAuthCore library which is developed by atebits who is the developer of Tweetie a.k.a. Twitter for Mac/iPhone. atebits / OAuthCore / overview – Bitbucket A sample code is [...]]]></description>
			<content:encoded><![CDATA[				<p>ASIHTTPRequest is a brilliant library, when you want to handle HTTP requests.<br />
				At this time, however, this library doesn&#8217;t support OAuth.</p>
				<p>You can support it easily with OAuthCore library which is developed by atebits who is the developer of Tweetie a.k.a. Twitter for Mac/iPhone.<br />
				<a target="_blank" href="https://bitbucket.org/atebits/oauthcore">atebits / OAuthCore / overview – Bitbucket</a></p>
				<p>A sample code is following.</p>
				<pre class="brush: objc; title: ; notranslate">#import &quot;OAuthCore.h&quot;

NSString * const CONSUMER_KEY = @&quot;YOUR_CONSUMER_KEY&quot;;
NSString * const CONSUMER_SECRET = @&quot;YOUR_CONSUMER_SECRET&quot;;
NSString * const ACCESS_TOKEN = @&quot;YOUR_ACCESS_TOKEN&quot;;
NSString * const ACCESS_TOKEN_SECRET = @&quot;YOUR_ACCESS_TOKEN_SECRET&quot;;

NSURL *URL = [NSURL URLWithString:@&quot;http://example.com/api&quot;];
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:URL];

[request setPostValue:@&quot;test&quot; forKey:@&quot;test_value&quot;];
[request buildPostBody];

NSString *header = OAuthorizationHeader([request url],
                                        [request requestMethod],
                                        [request postBody],
                                        CONSUMER_KEY,
                                        CONSUMER_SECRET,
                                        ACCESS_TOKEN,
                                        ACCESS_TOKEN_SECRET);

[request addRequestHeader:@&quot;Authorization&quot; value:header];</pre>
				<p>If you want to get &#8220;Access Token&#8221; and &#8220;Access Toke Secret&#8221;, such as you authorize with xAuth, you should set both ACCESS_TOKEN and ACCESS_TOKEN_SECRET, not nil but @&#8221;".</p>
				<h2>References</h2>
				<ul>
				<li><a target="_blank" href="http://groups.google.com/group/asihttprequest/browse_thread/thread/57e8d27717a44671">Oauth signing &#8211; ASIHTTPRequest | Google グループ</a></li>
				<li><a target="_blank" href="http://d.hatena.ne.jp/sugyan/20100819/1282156751">Objective-C向けOAuthライブラリ&#8221;OAuthCore&#8221;を使ってTwitter APIを叩いてみる &#8211; すぎゃーんメモ</a> (In Japanese)</li>
				</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.cocoalife.net/2011/01/post_865.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>xAuth Consumer Sample using Ruby</title>
		<link>http://www.cocoalife.net/2011/01/post_864.html</link>
		<comments>http://www.cocoalife.net/2011/01/post_864.html#comments</comments>
		<pubDate>Fri, 21 Jan 2011 03:57:09 +0000</pubDate>
		<dc:creator>milkcocoa</dc:creator>
				<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://www.cocoalife.net/?p=864</guid>
		<description><![CDATA[I&#8217;m developing OAuth/xAuth Service Provider using OAuth / OAuth-Plugin. pelle/oauth-plugin &#8211; GitHub Since OAuth-Plugin doesn&#8217;t support xAuth, I decided to create a program to support it. I&#8217;ll write an entry about xAuth support, before that, I write this entry about sample of using xAuth in Ruby. You need to install Ruby OAuth Gem. References POST [...]]]></description>
			<content:encoded><![CDATA[				<p>I&#8217;m developing OAuth/xAuth Service Provider using OAuth / OAuth-Plugin.<br />
				<a target="_blank" href="https://github.com/pelle/oauth-plugin">pelle/oauth-plugin &#8211; GitHub</a></p>
				<p>Since OAuth-Plugin doesn&#8217;t support xAuth, I decided to create a program to support it.<br />
				I&#8217;ll write an entry about xAuth support, before that, I write this entry about sample of using xAuth in Ruby.</p>
				<p>You need to install Ruby OAuth Gem.</p>
				<pre class="brush: ruby; title: ; notranslate">require 'oauth'

CONSUMER_KEY = 'Your-Consumer-Key'
CONSUMER_SECRET = 'Your-Consumer-Secret'

def get_access_token
  consumer = OAuth::Consumer.new(CONSUMER_KEY, CONSUMER_SECRET, :site =&gt; 'Your-OAUTH-Provider-URL')
  access_token = consumer.get_access_token(nil, {}, { :x_auth_mode =&gt; 'client_auth', :x_auth_username =&gt; 'Your-User-Name', :x_auth_password =&gt; 'Your-Password' })

  [access_token.token, access_token.secret]
end

def access_api(token, secret)
  consumer = OAuth::Consumer.new(CONSUMER_KEY, CONSUMER_SECRET, :site =&gt; 'Your-OAuth-Provider-URL')
  access_token = OAuth::AccessToken.new(consumer, token, secret)

  access_token.get('Your-API-URL')
end

token, secret = get_access_token
p &quot;token: #{token}&quot;
p &quot;secret: #{secret}&quot;

response = access_api(token, secret)
p response</pre>
				<h2>References</h2>
				<ul>
				<li><a target="_blank" href="http://dev.twitter.com/doc/post/oauth/access_token">POST oauth/access_token | dev.twitter.com</a></li>
				<li><a target="_blank" href="http://d.hatena.ne.jp/lyokato/20100212/1265961914">OAuthでデスクトップアプリがブラウザを経由させたくないときのxAuth &#8211; Codin’ In The Free World</a> (In Japanese)</li>
				<li><a target="_blank" href="http://blog.livedoor.jp/maraigue/archives/1109122.html">Maraigue風。:[Ruby][Twitter] OAuthのアクセストークンを、ブラウザなしで、Twitterのユーザ名およびパスワードのみを用いて取得する(通称：xAuth)ためのRubyのコード</a> (In Japanese)</li>
				</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.cocoalife.net/2011/01/post_864.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Find Skype Chat ID with rb-skypemac</title>
		<link>http://www.cocoalife.net/2011/01/post_863.html</link>
		<comments>http://www.cocoalife.net/2011/01/post_863.html#comments</comments>
		<pubDate>Mon, 10 Jan 2011 11:44:28 +0000</pubDate>
		<dc:creator>milkcocoa</dc:creator>
				<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://www.cocoalife.net/?p=863</guid>
		<description><![CDATA[Each Skype chat has an unique chat ID like &#8220;#hogehoge/XXXXXXXXXXXXXXXX&#8221;. This ID has very important role when you handle Skype with another programs/scripts like rb-skypemac (Ruby Gem). rb skypemac There is a very simple method to find IDs with rb-skypemac. After this command, you should select the appropriate ID.]]></description>
			<content:encoded><![CDATA[				<p>Each Skype chat has an unique chat ID like &#8220;#hogehoge/XXXXXXXXXXXXXXXX&#8221;.<br />
				This ID has very important role when you handle Skype with another programs/scripts like <a target="_blank" href="http://rb-skypemac.rubyforge.org/">rb-skypemac (Ruby Gem)</a>.<br />
				<a target="_blank" href="http://rb-skypemac.rubyforge.org/">rb skypemac</a></p>
				<p>There is a very simple method to find IDs with rb-skypemac.</p>
				<pre class="brush: ruby; title: ; notranslate">irb &gt; require 'rb-skypemac'
 =&gt; true
irb &gt; SkypeMac::Skype.send_(:command =&gt; 'SEARCH RECENTCHATS')
 =&gt; &quot;CHATS #hogehoge/XXXXXXXXXXXXXXXX, #piyopiyo/XXXXXXXXXXXXXXXX&quot;</pre>
				<p>After this command, you should select the appropriate ID.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.cocoalife.net/2011/01/post_863.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

