l'essentiel est invisible pour les yeux

Monday, June 30, 2008

Tutorial for how to create Erlang linked-in driver.

Erlang provides mechanism to communicate between Erlang and other programs written by C/C++ or other. This entry introduce how to create simple linked-in driver. Create shared library and Erlang interface to use Erlang's linked-in driver.

Goal: To create HAVAL bindings for Erlang.
HAVAL is fast cryptographic hash algorithm is invented by Yuliang Zheng, Josef Pieprzyk, and Jennifer Seberry in 1992. This library is pretty simple, so this is good choice for this tutorial.

Step 0: Files


config.h (Generated by configure script in HAVAL package)
haval.h
haval.c
haval.erl
haval_drv.cc
Makefile


haval.c and haval.h are included haval-1.1.tar.gz (C source code).

You can checkout these sample sources with Git. see haval_erlang.

% git clone git://github.com/rakuto/erlang_haval.git erlang_haval


Step 1: Create Erlang's interface
Erlang provides port mechanism in order to communicate between Erlang and other loaded shared object. See also Writing an Erlang Port using OTP Principles


-module(haval).
-author('Rakuto Furutani <xri://=rakuto>').

-define(DRV_INFO, 1).
-define(DRV_HAVAL_STRING, 2).
-define(DRV_HAVAL_FILE, 3).

-export([start/0, stop/0]).
-export([info/0, haval_string/1, haval_file/1]).
-ifdef(debug).
-export([test/0, test/1]).
-endif.

%%
%% Public interface
%%
start() ->
start("haval_drv"),
ok.

start(SharedLib) ->
case erl_ddll:load_driver(".", SharedLib) of
ok -> ok;
{error, already_loaded} -> ok;
_ -> exit({error, could_not_load_driver})
end,
register_lib(SharedLib).

stop() ->
[{port, Port}| _] = ets:lookup(haval_table, port),
Port ! {close, self()},
ok.

%% TODO: Implement this function return the information for module
info() -> ok.

%% Caluculate a value of HAVAL from string
haval_string(Str) ->
binary_to_term(control(?DRV_HAVAL_STRING, Str)).

%% Caluculate a value of HAVAL from file
haval_file(FileName) ->
binary_to_term(control(?DRV_HAVAL_FILE, FileName)).

-ifdef(debug).
test() ->
haval:start(),
Str = "I love Erlang.",
FileName = "haval.erl",
Hash1 = haval:haval_string(Str),
Hash2 = haval:haval_file(FileName),
io:format("HAVAL(~p) = ~p ~n", [Str, Hash1]),
io:format("HAVAL(~p) = ~p ~n", [FileName, Hash2]),
haval:stop(),
halt().

test([Str|_]) ->
haval:start(),
Hash = haval:haval_string(Str),
io:format("HAVAL(~p) = ~p ~n", [Str, Hash]),
haval:stop(),
halt().
-endif.

%%
%% Internal functions
%%
register_lib(SharedLib) ->
Port = open_port({spawn, SharedLib}, []),
Tab = ets:new(haval_table, [set, protected, named_table]),
ets:insert(Tab, {port, Port}).

control(Cmd, Data) ->
[{port, Port}| _] = ets:lookup(haval_table, port),
erlang:port_control(Port, Cmd, Data).



Step 2: Create C/C++ shared library
Shared library writted by C++ is loaded by Erlang interface when call erl_ddll::load_driver/2. This driver uses ei library in order to manipulate Erlang binary term.


/**
* HAVAL (cryptographic hash function) bindings for Erlang
*
* @author Rakuto Furutani <xri://=rakuto>
* @date 2008/06/28
*/
#include <stdio.h>
#include <string.h>
#include <stdarg.h>
#include <new>
#include "ei.h"
#include "erl_driver.h"
#include "erl_interface.h"
extern "C" {
// Define constant for haval.h
#define PASS 3
#define NUMBER_OF_BLOCKS 5000
#define FPTLEN 256
#ifndef LITTLE_ENDIAN
#define LITTLE_ENDIAN 1
#endif

#include "haval.h"
}

// Functions are provided by this driver
#define DRV_INFO 1
#define DRV_HAVAL_STRING 2
#define DRV_HAVAL_FILE 3

/* Driver Interface Declarations */
static ErlDrvData start_haval_driver(ErlDrvPort port, char *command);
static void stop_haval_driver(ErlDrvData drv_data);
static int control(ErlDrvData drv_data, unsigned int command, char *buf,
int len, char **rbuf, int rlen);
static void haval_to_hex(unsigned char*, char*);
static ErlDrvBinary* ei_x_to_new_binary(const ei_x_buff*);

/* Driver Entry */
static ErlDrvEntry haval_driver_entry = {
NULL,
start_haval_driver,
stop_haval_driver,
NULL,
NULL,
NULL,
"haval_drv",
NULL,
NULL,
control,
NULL,
NULL
};

typedef struct _drv_data {
ErlDrvPort port;
} drv_data_t;

/* DRIVER INTERFACE */

static ErlDrvData start_haval_driver(ErlDrvPort port, char *command)
{
drv_data_t *data;

data = (drv_data_t*) driver_alloc(sizeof(drv_data_t));
data->port = port;
set_port_control_flags(port, PORT_CONTROL_FLAG_BINARY);
return (ErlDrvData) data;
}

static void stop_haval_driver(ErlDrvData drv_data)
{
driver_free((char*) drv_data);
}

static int control(ErlDrvData drv_data, unsigned int command, char *buf, int len, char **rbuf, int rlen)
{
int ret = -1;
char hex[(FPTLEN >> 3) << 1];
unsigned char fingerprint[FPTLEN >> 3];
char *arg1;
ei_x_buff x_buff;

try {
// argument
arg1 = new char[len + 1];
strncpy(arg1, buf, len);
strcat(arg1, "�0");

ei_x_new_with_version(&x_buff);
switch(command) {
case DRV_INFO:
ei_x_encode_string(&x_buff, "info");
ret = sizeof("info") * sizeof(char);
break;
case DRV_HAVAL_STRING:
haval_string(arg1, fingerprint);
haval_to_hex(&fingerprint[0], &hex[0]);
ret = sizeof(hex);
ei_x_encode_string(&x_buff, hex);
break;
case DRV_HAVAL_FILE:
if(!haval_file(arg1, fingerprint)) {
haval_to_hex(&fingerprint[0], &hex[0]);
ret = sizeof(hex);
ei_x_encode_string(&x_buff, hex);
} else {
erl_err_sys("haval_file");
}
break;
}
if(ret > 0) *rbuf = reinterpret_cast<char*>(ei_x_to_new_binary(&x_buff));
ei_x_free(&x_buff);
} catch(std::bad_alloc) {
erl_err_sys("can not allocate memory");
}

return ret;
}

static void haval_to_hex(unsigned char *fingerprint, char *hex)
{
for(int i=0; i < FPTLEN >> 3; ++i) {
sprintf(&hex[i << 1], "%02X", fingerprint[i]);
}
}

// Init the driver
extern "C" DRIVER_INIT(haval_drv)
{
return &haval_driver_entry;
}

// Utilities
static ErlDrvBinary* ei_x_to_new_binary(const ei_x_buff *x_buff)
{
ErlDrvBinary *bin = driver_alloc_binary(x_buff->index);
if(bin != NULL) {
memcpy(bin->orig_bytes, x_buff->buff, x_buff->index);
}
return bin;
}


Step 3: Compile all sources
Create Makefile for build.
FYI: If you want to build linked-in driveron Mac OS, see Compile Erlang linked-in driver on Mac OSX (Darwin)


.PHONY: clean
.SUFFIXES: .o .c .cc .erl .beam

OS= ${shell uname}
CC=gcc
CXX=g++
CXXFLAGS=-Wall -g

# Erlang
ERL_INCLUDE = -I/usr/local/lib/erlang/usr/include
ERL_LIBS = -L/usr/local/lib/erlang/usr/lib \
-lerts
EI_INCLUDE = -I/usr/local/lib/erlang/lib/erl_interface-3.5.6/include
EI_LIBS = -L/usr/local/lib/erlang/lib/erl_interface-3.5.6/lib \
-lei \
-lerl_interface

TARGET_LIB = haval_drv.so
ifeq ($(OS), Darwin)
EXTRA_OPTIONS = -fno-common -bundle -undefined suppress -flat_namespace
endif
ALL: $(TARGET_LIB) haval.beam

.erl.beam:
erlc -W -Ddebug $<

.c.o:
$(CC) $(CFLAGS) -c $<

.cc.o:
$(CXX) $(CXXFLAGS) $(ERL_INCLUDE) $(EI_INCLUDE) -c $<

haval_drv.so: haval.o haval_drv.o
$(CXX) -o $@ $^ $(ERL_LIBS) $(EI_LIBS) $(EXTRA_OPTIONS) -fpic -O2

clean:
rm -f *.beam *.o *.so



Step 4: Run and test

% erl -noshell -run haval test
HAVAL("I love Erlang.") = "3AECEDF5133ED147C704A25C2CCA9A994FBB984FBCB22C1A523F31963E418498"
HAVAL("haval.erl") = "E006098555DFF788E73C7A263615DF60CC82396B1BCE7AEB5FB7050C376F2B03"

Saturday, June 28, 2008

Compile Erlang linked-in driver on Mac OSX (Darwin)

In order to compile the Erlang linked-in driver on Darwin, we must specify some options when it will be linked. If you don't specify these options, you might see errors is as follows:

% gcc -o my_drv.dymlib my_drv.c -dynamiclib -fpic

/usr/bin/ld: Undefined symbols:
_driver_alloc
_driver_free
_driver_output

That's invalid, so it must specify some options below in order to create the shared object.

% gcc -o my_drv.so my_drv.c -bundle -flat_namespace -udefined suppress


see README in source code of Erlang/OTP for more details.

Friday, June 27, 2008

Asynchronous driver in Erlang using driver_async

Erlang provides some mechanism is to communicate other language, this can be used for to reuse module, speed things up (Erlang is ten times as slow as slow than C), to access OS resource and so on. The below mechanism are provided.

Pipe Drivers
The "pipe drivers" enables bi-directional communication. The external process can be implemented in C or any language, and it can use erl_interface and ei library in order to manipulate data of Erlang as ETERM.

Benefit:

  • Frexible, it can use some types data.
  • Any language

Demerit:
  • Communication overhead

Linked-in Drivers
A driver in Erlang is a library written in C/C++, that is linked to the Erlang emulator and called from erlang. A driver can be dynamically loaded, as a shared library (known as a DLL on windows), or statically loaded, linked with the emulator when it is compiled and linked.

Benefit:
* Faster than "Pipe Drivers"

Demerit:
* Not frexible, to pass the complex data between C/C++ and Erlang is difficult. (see also ei)


Asynchonous Linked-in Driver
The "Linked-in Drivers" is faster than "Pipe Drivers", but it can not scale with a lot of process, since it run synchronously. So If you'd like to take advantage of platforms with multiple CPUs, then you must run some Erlang virtual machine since it run on single thread.

It sounds like great!, but we should care the some problems, multi-thread problem and so on.

Resources:

Next, I'll write an entry about how to create asynchronous driver.

Wednesday, June 18, 2008

[EC2] mount /dev/sdc device since /dev/sdb is not available

AWS team announced about persistent storage, see below the link.

http://www.allthingsdistributed.com/2008/04/persistent_storage_for_amazon.html

That's looks like pretty cool, but it's closed beta now, so we should use S3 or EC2 ephemeral storage (aka. Instance Storage). The 160GB storage is available on m1.large AMI, and some below devices are available.

/dev/sda1 Formatted and mounted as root (/) on all instance types
/dev/sda2 Formatted and mounted as /mnt on small instances
/dev/sda3 Formatted and mounted as /swap on small instances
/dev/sdb Formatted and mounted as /mnt on large and extra large instances
/dev/sdc Available on large and extra large instances; not mounted
/dev/sdd Available on extra large instances; not mounted
/dev/sde Available on extra large instances; not mounted


ATTENTION: The /dev/sdb isn't mounted to /mnt on m1.large AMI, see below a link for more details.
But the /dev/sdb device looks like that isn't mounted to /mnt.


% df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 9.9G 8.6G 801M 92% /
tmpfs 3.8G 0 3.8G 0% /lib/init/rw
udev 10M 10M 0 100% /dev
tmpfs 3.8G 4.0K 3.8G 1% /dev/shm
%


/dev/sdb is recognized in /etc/fstab, but it isn't mounted.

# Default /etc/fstab
# Supplied by: ec2-ami-tools-1.3-20041
/dev/sda1 / ext3 defaults 1 1
/dev/sdb /mnt ext3 defaults 0 0
none /dev/pts devpts gid=5,mode=620 0 0
none /proc proc defaults 0 0
none /sys sysfs defaults 0 0



% sudo mount /mnt
mount: /dev/sdb is not a valid block device


So we should initialize device to use as file system.
At first, optimize virtual devices before use them in production.

dd if=/dev/zero of=/dev/sdb bs=1M
dd if=/dev/zero of=/dev/sdc bs=1M
dd if=/dev/zero of=/dev/sdd bs=1M (m1.xlarge only)
dd if=/dev/zero of=/dev/sde bs=1M (m1.xlarge only)


Create a file system and mount it, and mounted /dev/sdc device is available now.

mkfs -t ext3 /dev/sdc
mount -t ext3 /dev/sdc /www



Filesystem Size Used Avail Use% Mounted on
/dev/sda1 9.9G 8.2G 1.2G 88% /
tmpfs 3.8G 0 3.8G 0% /lib/init/rw
udev 10M 10M 0 100% /dev
tmpfs 3.8G 4.0K 3.8G 1% /dev/shm
/dev/sdc 414G 6.7G 386G 2% /www

Tuesday, June 17, 2008

グラデーションブックスで本を探そう。amazonのおすすめ本ばかり読んでいたら世界が広がらない。


Photo via Flickr

グラデーションブックス

amazonの本ランキングや、楽天ブックスの本ランキングは、読者に新しい発見や本をブラウズする楽しみをもたらしているだろうか?実は、深いつながりがある、経済学の本と、最近話題のKYについて書いた本を一緒にリコメンドするだろうか?島嶼http://www.blogger.com/img/gl.link.gif生物学と企業の経営について、二つの本を結びつける事ができるだろうか?

先日、クローズアップ現代「ランキンhttp://www.blogger.com/img/gl.link.gifグ依存が止まらない」で、出版業界が抱える問題にスポットを当てた特集が放送された。とても素晴らしいまとめ記事が2008-06-04 今日の「クローズアップ現代」にある。
出版ニュース社の清田代表は、「ランキングで売れているからそれでいいというわけではない。出版の世界は奥が深いし、多様なものがあって、いろんな面白い本がある。むしろ、売れない本、売りにくい本こそ、いい本があって、埋もれてしまっている状況だ」


そのような状況の中、本を扱うサイト「グラデーションブックス」がオープンした。サイトの運営元である、澁川直子氏の言葉を引用する。

「従来の目的型検索やリコメンデーションサービスでは出会うことができな
かった、思いもよらない本を見つけ出せる喜びを提供できればと思います。」


amazonのリコメンドでは、思いもよらなかった発見が無い。極端な言い方をしてしまえば、amazonのオススメ本ばかり読んでいては、世界観が広がらない。だからこそ、人は、本屋に足を運び、本を買う。本好きの知人から、面白い本について教えてもらう。憧れている人が読んでいる本を、自分も読む。

上記に引用したブログ中にも書かれている通り、ランキングを見て本を購入する読者は、年に本を数冊しか読まないユーザである。たくさんの本を読んでいる人は、複数のジャンルを超えて、面白い本を発見し、つながりを見つけ出す英知を持っている。年間数冊しか読まない読者も、年間200冊読む読者と同じように、面白い本に出会えるサイトが、グラデーションブックスであるような気がしている。

技術本やビジネス本などの実用書しか読まなかった私も、このサービスをきっかけに小説やミステリーを読み出してみた。そんな、きっかけを与えてくれた面白い本を集めてくれている本棚をいくつかリンク。

chibinaoさん
Junさん
yukoさん
Saitoさん

Monday, May 19, 2008

[rails] RSpec matchers for render(:nothing => true)

This is matchers for render(:nothing => true).

Add some code into spec/spec_helper.rb is as follows:


# Matchers for render(:nothing => true)
class RenderNothing
def initialize
end

def matches?(controller)
@actual = controller.rendered_file
@actual == nil
end

def failure_message
return "render_nothing expected (render :nothing => true), got #{@actual.inspect}"
end

def negative_failure_message
return "render_nothing expected (render :nothing => true) not to equal #{@actual.inspect}"
end
end

def render_nothing
RenderNothing.new
end


Use render_nothing.

it "should not render anything" do
post :destroy, :id => 1
response.should render_nothing
end

Sunday, May 18, 2008

[rails] RSpec render_layout expects render specified layout file

Original idea via http://rubyforge.org/pipermail/rspec-users/2007-October/004026.html

Add some code into your spec/spec_helper.rb is as follows:


class RenderLayout
def initialize(expected)
@expected = 'layouts/' + expected
end

def matches?(controller)
@actual = controller.layout
@actual == @expected
end

def failure_message
return "render_layout expected #{@expected.inspect}, got #{@actual.inspect}", @expected, @acutual
end

def negative_failure_message
return "render_layout expected #{@expected.inspect} not to equal #{@actual.inspect}", @expected, @actual
end
end

def render_layout(expected)
RenderLayout.new(expected)
end

your_controller_spec.rb

it "should render 'application' layout file" do
get :index
response.should render_layout('application')
end

Tuesday, May 06, 2008

[rails] Running Erubis on Edge Rails

ActionView class was refactoring on Edge Rails, see Ticket #10437 for more details. The template engines are integrated into new ActionView::Template class, but we have to modify some scripts in order to run Erubis on Edge Rails.

0. Install Erubis and Edge Rails

% sudo gem install erubis
% cd /path/to/rails_app/ && rake rails::freeze:edge

1. Create a template handler for Erubis.

Copy and paste below code at #{RAILS_ROOT}/lib/erubis_rails_helper.rb.
require 'erubis'
require 'erubis/preprocessing'

module Erubis
class Eruby
include ErboutEnhancer
end

class FastEruby
include ErboutEnhancer
end
end

module ActionView
module TemplateHandlers
class Erubis < TemplateHandler
include Compilable

# Erubis engine class
cattr_accessor :engine_class
@@engine_class = ::Erubis::Eruby

# Properties
cattr_accessor :init_properties
@@init_properties = {}

# Enable preprocessing if true
cattr_accessor :preprocessing
@@preprocessing = false

def compile(template)
if preprocessing
preprocessor = ::Erubis::PreprocessingEruby.new(template, init_properties)
template = preprocessor.evaluate(@view)
end
engine_class.new(template, init_properties).src
end
end
end
end
ActionView::Template.register_default_template_handler :erb, ActionView::TemplateHandlers::Erubis
ActionView::Template.register_template_handler :rhtml, ActionView::TemplateHandlers::Erubis

2. Configure settings of Erubis in enviroment.rb.

Append below scripts in config/enviroment.rb
require 'erubis_rails_helper'
ActionView::TemplateHandlers::Erubis.engine_class = Erubis::FastEruby
ActionView::TemplateHandlers::Erubis.preprocessing = true
Restart the web server.

Saturday, May 03, 2008

[rails] released jrails_in_place_editing

The jrails_in_place_editing is implementation of inplace editor with jQuery, so this plugin is dependent on jRails. This uses David Hauenstein's jQuery inplace editor plugin. Thank you.

INSTALL (Note: Edge Rails)


./script/plugin install git://github.com/rakuto/jrails_in_place_editing.git

USAGE

# Controller
class BlogController < ApplicationController
in_place_edit_for :post, :title
end

# Customize the action that update the value
class BlogController < ApplicationController
# set_#{object}_#{title}
def set_post_title
post = Post.find(params[:id])
post.title = params[:value]
post.save

# It should render a text
render :text => post.title
end
end

# View
<%= in_place_editor_field :post, :title %>

# Pass some options
<%= in_place_editor_field :post, :title, {}, {:field_type => 'textarea', :textarea_cols => 25, :textarea_rows => 10}%>
<%= in_place_editor_field :post, :title, {}, {:field_type => 'textarea', :textarea_rows => 10}%>

For more details, see jrails_inplace_editing/javascripts/jquery.inplace.js

Tuesday, April 29, 2008

Edge Rails: Describes Gem Dependencies

So far today, Gem dependencies might be written with Capistrano, but we can write Gem dependencies in config/environemt.rb with Edge Rails, and it will be installed with Rake task.

# in config/enviroment.rb


config.gem 'hpricot'
config.gem 'aws/s3', '>= 0.4.0'
config.gem 'aws-s3', :lib => 'aws/s3', :version => '>= 0.4.0', :source => "http://code.whytheluckystiff.net"


Install all required Gems.
rake gems:install

Cool

Saturday, April 26, 2008

OpenID再利用問題

ドメインの更新忘れもOpenIDにおける脆弱性の一つ。

URLやXRIを入力するだけで、Yadisプロトコルに基づきOpenIDプロバイダーやi-Brokerを発見し、認証が行えるシステムは、とてもシンプルでありながら、WWWの分散アーキテクチャの上に構築された強力なエコシステムだ。しかし、問題は、私達自身の識別子として利用可能なURLやXRIは、永遠ではないことだ。

もしも、私達が利用しているOpenIDプロバイダがドメインの更新を忘れて、第三者にドメインが取得された場合、私達のアカウントがこの第三者により不正に使用される可能性が出てくる。myOpenIDや、多くのプロバイダでは、単純なルールに基づいた、Human FriendlyなOP-Local Identifierを提供してくれているが、ユーザは、セキュリティ的、高可用性の両方の側面からRelying Partyでのユーザ登録に、OP-Local Identifierを使用すべきではない。

もう少し、現実的に起こりえそうな問題は、OpenIDプロバイダにより特定のアカウントの持ち主が変更されたケースである。初めは、Aというユーザが、a.example.comというOP-Local Identifierを保持していたが、Aが退会して同じOP-Local IdentifierがBというユーザに渡った場合、Bは、AがOP-Local Identifierを用いて会員登録したRPにサインインして登録された情報に自由にアクセスすることができる。

もう一つの問題は、自分のHPのURLを識別子として利用した場合のリスクである。この場合、自分がドメインの更新を忘れて(または意図的に)、ドメインが第三者の手に渡ると、Relying Party上に残した私達の情報が、第三者に再利用される可能性が生まれる。

どちらの問題も、OPでのアカウントのExpireや移行がRPと同期できないために発生する問題である。
既存のOpenIDライブラリ(といっても、ruby-openidしか見ていない)では、OpenID URLの変更とアクティベーションのサンプルはついていないが、RPはこの機能を用意すべきだろう。

OpenID再利用問題一つとっても認証をOpenIDのみに踏み切るには、まだまだリスクが高い。

P.S.
念のため補足すると、XRIでは再利用の問題が起きない。これは、XRIが取得される度にi-Numberと呼ばれる全世界で一意な値を割り当てるからである。XRIでは、このi-NumberがClaimed Identifier(aka XRDS::XRD::CanonicalEquivID)になるからである。

myOpenIDなどユーザのセキュリティに対して十分な対応をしているプロバイダでは、一度取得されたアカウントは、退会した後も再利用される事は無いのでここに書いた問題は発生しない。ただし、退会後のアカウントについて明記していないプロバイダは要注意である。

Wednesday, April 23, 2008

DRY routing with form generated by Rails helper methods, shouldn't write routings directly in Javascript code.

The routing solution in Rails is pretty powerful, so we can modify routing easiliy. This facility may become cause of bugs. If we wanna submit data asynchronously with Javascript, then we have to write some routing paths in source of Javascript directly. It's not DRY and it doesn't work together with Rails routing solution.

So we think example code which post a comment to the article. We have two resources, articles, comments.


map.resources :articles, :has_many => [:comments]


In this case, I guess most people use helper methods which built in rails.

<% # The generated path (aka action) is same as "/articles/:article_id/comments" %>
<% remote_for_for([@article, Comment.new]) do |f| %>
<%= f.text_field :body %>
<%= submit_tag 'Post' %>
<% end %>


It's just simple, not a problem.

Imagine create a basket like shopping card, it supports drag and drop user interface. We can drag products or image into basket. This example has routings is as follows:

map.resource :basket, :has_many => [:items]


And we have to implement drag and drop user interface, following code is sample implementation with jQuery. It has URL where submits item data. If someone will change Rails routings, this code will be sucks.


$(function(){
// FIXME: It's not DRY
var ADD_ITEMS_TO_BASKET_PATH = '/basket/items';

$('img.draggableItem').draggable();
$('#basket').droppable({
drop: function(e) {
$.ajax({
url: ADD_ITEM_TO_BASKET_PATH,
type: 'post',
success: function(){}
});
}
});
});

So I guess we should use forms generated by Rails helper methods, and It set form's visibility is hidden. You set a required data into fields, and submit the form.

In Rails view:

<% remote_form_for([@basket, Item.new], :html => {:id => 'add_to_basket', :style => 'display:none'}) do |f| %>
<%= f.hidden_field :id %>
<%= submit_tag 'Add an item' %>
<% end %>

In Javascript:

$(function(){
$('img.draggableItem').draggable();
$('#basket').droppable({
drop: function(e, ui) {
var itemId = itemId(e.target);
var form = $('#add_to_basket');
form.find('> input[name="item[id]"]').val(itemId);
$('#add_to_basket > input[type="submit"]').click();
}
});
});


In this case, we don't need to write any routings directly in Javascript, so It's DRY.

Monday, April 21, 2008

rubyonrails.org isn't available now?

It might forget to update a domain name, so we can't see rubyonrails.org.


% whois rubyonrails.org
Last Updated On:20-Apr-2008 18:08:51 UTC
Expiration Date:19-Apr-2009 22:40:29 UTC


We can access rubyonrails.com, .net instead of .org.

See also
http://www.ruby-forum.com/topic/150274

Sunday, April 20, 2008

瀧内メソッドで開催された第0回OpenID勉強会に第一回はない

第0回OpenID勉強会が開催されました。

写真は、OpenID勉強会レポートより拝借。

全くのノープラン、セッションの詳細無しにも関わらず、20人ものOpenID野郎達が集まりました。
Identity界隈には、男しかいないのでしょうか。

参加者
全体的に、LL使いの人達が多く集まったようでした。プログラマではない方も2名いて、企業におけるOpenID導入における苦労話や、Yahoo!の中のアカウントをOpenID化する際のセキュリティポリシーに対する考えなどを話してもらえました。

全員参加型勉強会では、20人/セッションまで
今回もComet勉強会を彷彿とさせる、瀧内メソッドにより内容の充実した勉強会が開催できました。全員参加型のセッションが開催できるのは、このメソッドの良い所。しかし、最大の欠点が、続く第1回OpenID勉強会を開催するとすれば話す事が無い事。こちらもComet勉強会を彷彿とさせます。次回開催できるとすれば、OpenIDに限らず、より話を広げて、Digital Identity全体、Social Webなどの話になるかもしれません。

勉強会に来るプログラマには、ブラックボックスを刺激しろ
勉強会に足を運ぶプログラマたちは、「なぜかよくわからないけど動作している」といったブラックボックスが気になっているのではないでしょうか。OpenIDにおいても、ライブラリが充実しているので、「詳細がわからないけど、使えている。」「時間がなくて、動作原理やスペックを追えていない。」というプログラマが多いはず。勉強会中にも出ていた、「仕様書をしっかりと読み、動作原理を理解する事は、自信につながる」という話。今日から、「俺、OpenID知ってるぜ」と人に言えるようになったかも?しれません。

セッションの方は、ZIGOROuさんの飛び入りセッション2本も入り、とても充実。ありがとうございました。

懇親会は、6時間の長丁場
ピッチャーも10杯以上は出たのでは?という6時間の長丁場。懇親会は、勉強会第二ラウンド。こちらでは、OpenIDに止まらず、色々な話ができました。

今後のOpenID界隈の話は、次の場所で開催していますので、ご参加ください。

OpenID勉強会 hosted by rfurutani.

Join now


Chat about what's on your mind. More about public chats.


http://groups.google.com/group/openid-ja
IRC: #openid-ja@freenode

Special Thanks
Drecom (会場提供)
Genki (オーナー)

See also
OpenID勉強会レポート
id:ZIGOROu - OpenID勉強会に行って来ました
onk-san - OpenID 勉強会に行ってきました。
matake-san - OpenID勉強会@ドリコム恵比寿オフィス

Monday, April 14, 2008

OP Identifier and Claimed Identifier, easier OpenID Identifier.

It might be less well know, we can sign in with only OP Identifier(myopenid.com, yahoo.com etc.) into RP respond to OpenID authentication. For example, I have a myOpenID account in Rakuto Furutani. So I can sign in my OpenID URL (aka OP-Local Identifier), but I can also sign in into RP with only a OP's host name.



Why can we sign in with only a OP's host name(aka OP Identifier)?

1. First the OpenID library obtain Yadis Document from OP Identifier, It can emulate with curl script. This specification is part of a Yadis Specification.


% curl -H "Accept: application/xrds+xml" http://www.myopenid.com/

Take a response as XRDS

<?xml version="1.0" encoding="UTF-8"?>
<xrds:XRDS
xmlns:xrds="xri://$xrds"
xmlns="xri://$xrd*($v*2.0)">
<XRD>

<Service priority="0">
<Type>http://specs.openid.net/auth/2.0/server</Type>
<Type>http://openid.net/sreg/1.0</Type>
<URI priority="0">http://www.myopenid.com/server</URI>
</Service>

</XRD>
</xrds:XRDS>


The OpenID client can obtain OP Endpoint URL, "http://www.myopenid.com/server", and the client is initiate the OpenID Authentication request with obtained OP Endopoint URL. If authentication will be success, take a response(aka Positive Assertion). It includes such as some paramters is as follows:


{"openid.claimed_id"=>"http://rakuto.myopenid.com/",
"openid.mode"=>"id_res",
"openid.return_to"=>"http://localhost:3000/consumer/complete",
"openid.sig"=>"4fAHQGtaUgCjsrMAfue/Qi+k32w=",
"openid.ns"=>"http://specs.openid.net/auth/2.0",
"openid.op_endpoint"=>"http://www.myopenid.com/server",
"openid.response_nonce"=>"2008-04-14T13:27:18ZCEGxaV",
"openid.identity"=>"http://rakuto.myopenid.com/",
"openid.assoc_handle"=>"{HMAC-SHA1}{4e02f931}{EAZGvE==}",
"openid.signed"=>
"assoc_handle,claimed_id,identity,mode,ns,op_endpoint,response_nonce,return_to,signed"}


The client library can obtain Claimed ID from openid.identity, and it can also obtain our XRDS.

<?xml version="1.0" encoding="UTF-8"?>
<xrds:XRDS
xmlns:xrds="xri://$xrds"
xmlns:openid="http://openid.net/xmlns/1.0"
xmlns="xri://$xrd*($v*2.0)">
<XRD>

<Service priority="0">
<Type>http://specs.openid.net/auth/2.0/signon</Type>
<Type>http://openid.net/sreg/1.0</Type>
<Type>http://openid.net/extensions/sreg/1.1</Type>
<Type>http://schemas.openid.net/pape/policies/2007/06/phishing-resistant</Type>
<Type>http://openid.net/srv/ax/1.0</Type>
<URI>http://www.myopenid.com/server</URI>
<LocalID>http://rakuto.myopenid.com/</LocalID>
</Service>

<Service priority="1">
<Type>http://openid.net/signon/1.1</Type>
<Type>http://openid.net/sreg/1.0</Type>
<Type>http://openid.net/extensions/sreg/1.1</Type>
<Type>http://schemas.openid.net/pape/policies/2007/06/phishing-resistant</Type>
<Type>http://openid.net/srv/ax/1.0</Type>
<URI>http://www.myopenid.com/server</URI>
<openid:Delegate>http://rakuto.myopenid.com/</openid:Delegate>
</Service>

<Service priority="2">
<Type>http://openid.net/signon/1.0</Type>
<Type>http://openid.net/sreg/1.0</Type>
<Type>http://openid.net/extensions/sreg/1.1</Type>
<Type>http://schemas.openid.net/pape/policies/2007/06/phishing-resistant</Type>
<Type>http://openid.net/srv/ax/1.0</Type>
<URI>http://www.myopenid.com/server</URI>
<openid:Delegate>http://rakuto.myopenid.com/</openid:Delegate>
</Service>

</XRD>
</xrds:XRDS>



Conclusion
If you use URL as OpenID Identifier, then you don't need to input "http://" and your Claimed Identifier because It's client library's work. Your Claimed Identifier is obtained by RP, so you just have to input your OPs host name.

e.g.) myopenid.com or yahoo.com etc.

Wednesday, April 02, 2008

4/19 OpenID勉強会のお知らせ

via OpenID勉強会のお知らせ

OpenID勉強会を開催します。
ドリコムさんの御好意により会場を貸していただけるようです。
ありがとうございます!

  • 日時: 4/19(土) 13:30~18:00
  • 場所: 株式会社ドリコム ミーティングルーム (地図) 
  • 準備: OpenIDの基礎知識。ノートPC、e-mobileがあるとなお良いです


以下のオープンチャットで、OpenID勉強会に関する雑談を開催しています。対岸の人達が面白くしてくれるだろうでは、残念すぎます。国内から世界に盛り上げましょう。今後必要になるOpenID Extension、 SOAPとOpenDI、ユーザ属性の交換とOP間での同期、OpenIDの未来予測、OpenIDとビジネス、Openである事とDataWeb、 地球規模で一意な識別子XRI、クロスドメインアプリケーション、などなどアツくアツく語り合いましょう。

OpenID勉強会 hosted by rfurutani.

Join now


Chat about what's on your mind. More about public chats.

Thursday, March 27, 2008

AWS EC2 announced that release Elastic IP which includes Static IP support and more !!

Wow!!

Feature Guide: Amazon EC2 Elastic IP Addresses

Amazon announced about Elastic IP. This solution is included static IP support and more. Many developers who use EC2 may become happy! The Elastic IP is associated with our account, not a paticular account, and Amazon EC2 enables us to engineer around problems with our instance or software by programmatically remapping your Elastic IP address to a replacement instance.

For details, see Feature Guide: Amazon EC2 Elastic IP Addresses.

Thanks AWS team!

Monday, March 24, 2008

[ruby] Why does StoreRequest of OpenID Attribute Exchange (AX) attract our heart? (and DEMO of AX StoreRequest with ruby-openid)

AX StoreRequest message is defined in OpenID Attribute Exchange 1.0. It can store personal identity information to the OpenID Provider from RP. It's exciting specification because we use many services on WWW, and input variety of many personal identity in sites. We can aggregate our personal identity automatically with AX StoreRequest message! Additionally, updated personal identity is synced AX's update_uri property across the all services!

Demo that sent AX StoreRequest message, and dispatch AX StoreResponse message with ruby-openid as follows.

At first, we need to extend ruby-openid to handle AX StoreRequest and StoreResponse usefully.
openid_ax_ext.rb


require 'rubygems'
require 'openid/extension'
require 'openid/message'

module OpenID
module AX
class StoreRequest
# Extract a StoreRequest from an OpenID message
def self.from_openid_request(oid_req)
message = oid_req.message
ax_args = message.get_args(NS_URI)
return nil if ax_args.empty?
req = new
req.parse_extension_args(ax_args)
req
end
end

class StoreResponse
def self.from_success_response(success_response)
resp = nil
ax_args = success_response.message.get_args(NS_URI)
resp = ax_args.key?('error') ? new(false, ax_args['error']) : new
end
end
end
end


app/controller/consumer_controller.rb

# in ConsumerController#start
# AX StoreRequest message
if params[:use_ax_store]
ax_store_req = OpenID::AX::StoreRequest.new
ax_store_req.set_values('http://axschema.org/contact/email', %w(rakuto@example.com rakuto@example2.com))
ax_store_req.set_values('http://axschema.org/birthDate', %w(1985-03-12))
ax_store_req.set_values('http://axschema.org/contact/IM/Skype', %w(rfurutani))
oidreq.add_extension(ax_store_req)
oidreq.return_to_args['did_ax_store'] = 'y'
end


Next, OP handles the request included StoreRequest message.
app/controller/server_controller.rb

# in ServerController#start
# Check the AX StoreRequest
@ax_store_req = OpenID::AX::StoreRequest.from_openid_request(oidreq)


And OP must save personal identity sent from RP.

# Extract Personal Identity from request and save it.
# Check the StoreaRequest for AX
ax_store_resp = nil
ax_store_req = OpenID::AX::StoreRequest.from_openid_request(oidreq)
if ax_store_req
begin
# I think all user's attribute should be saved, but table structure of RDBMS VERY statically.
# So we need to respond StoreResponse mode is 'store_response_failure'.
# In a nut shell, we may use XMLDB by now!
ax_store_req.data.each do |type_uri, values|
case type_uri
when 'http://axschema.org/email'
# XXX: This is dummy
user.emails.concat(values)
when 'http://axschema.org/birthDate'
# XXX: This is dummy
user.birth_date = Date.parse(values.first)
when 'http://axschema.org/contact/IM/Skype'
# XXX: This is dummy
# Just one
user.skype_id = values.first
else
ax_store_resp = OpenID::AX::StoreResponse.new(false, "#{type_uri} isn't supported Type URI in this service.")
end
end
user.save
rescue Error => e
ax_store_resp = OpenID::AX::StoreResponse.new(false, e.message)
end
end
oidresp.add_extension(ax_store_resp || OpenID::AX::StoreResponse.new)


This is the sample view for AX StoreRequest added the checkbox enable it.

<% if flash[:ax_store_results] %>
<div class='error'>
<%= flash[:ax_store_results] %>
</div>
<% elsif params[:did_ax_store] -%>
<div class='alert'>
Your Personal identity has saved.
</div>
<% end %>
<div id="verify-form">
<form method="get" accept-charset="UTF-8"
action='<%= url_for :action => 'start' %>'>
Identifier:
<input type="text" class="openid" name="openid_identifier" />
<input type="submit" value="Verify" /><br />
<input type="checkbox" name="immediate" id="immediate" /><label for="immediate">Use immediate mode</label><br/>
<input type="checkbox" name="use_sreg" id="use_sreg" /><label for="use_sreg">Request registration data</label><br/>
<input type="checkbox" name="use_pape" id="use_pape" /><label for="use_pape">Request phishing-resistent auth policy (PAPE)</label><br/>
<input type="checkbox" name="force_post" id="force_post" /><label for="force_post">Force the transaction to use POST by adding 2K of extra d
ata</label><br/>
<input type="checkbox" name="use_ax" id="use_ax" /><label for="use_ax">Request registration data with AX</label><br/>
<input type="checkbox" name="use_ax_store" id="use_ax_store" /><label for="use_ax_store">Request store attributes with AX</label>
</form>
</div>


Confirmation of stored personal identities.
app/views/server/decide.rhtml

<% # XXX: Part of axschema -%>
<% axschema_map = {
'http://axschema.org/birthDate' => 'Birthdate',
'http://axschema.org/contact/email' => 'Email',
'http://axschema.org/contact/IM/Skype' => 'Skype'
} -%>
<% # Is StoreRequest included in request? -%>
<% if @store_req -%>
<div class="attention">
<p>And do you accept following data sent from RP?</p>
<dl>
<% @store_req.data.each do |k,v| -%>
<dt><%= axschema_map[k] -%>:</dt>
<dd><%= h v.join(', ') -%></dd>
<% end -%>
</dl>
</div>
<% end -%>


Finally, request is coming back to RP, so We need to handle success response.
app/controllers/consumer_controller.rb

# in ConsumerController#complete
# for AX store
if params[:did_ax_store]
ax_store_resp = OpenID::AX::StoreResponse.from_success_response(oidresp)
flash[:ax_store_results] = ax_store_resp.error_message unless ax_store_resp.succeeded?
end


Screenshot
These screenshot are capture output of above code.


Confirmation of stored personal identities.


Conclusion
This future is pretty interesting, but it isn't suppoted even myOpenID now. In the future, I think many OP supports AX StoreRequest. I wish!

Saturday, March 22, 2008

[ruby] myOpenID and OpenID Attributes Exchange, myOpenID isn't supported Type URI described in http://axschema.org/

JanRain's myOpenID is popular OpenID provider, supports SSL, SREG, some persona, authentication with Information Card, OpenID Attributes Exchange (but only some attributes), Pavatar and so on. JanRain also offers ruby-openid that implements OpenID 2.0 with Ruby.

myOpenID supports only some attributes that can be exchange with OpenID Attribute Exchange, but you should care about Type URI, because myOpenID doesn't support Type URI described on "http://www.axschema.org/types/". You should specify Type URI with "http://schema.openid.net/" instead.

Sample code that fetch some attributes from myOpenID is as follows. At first, you need to initialize your persona. My persona for work is "Rakuto Furutani".

ConsumerController#start in /path/to/rails_openid/app/controller/consumer_controller.rb


# AX
if params[:use_ax]
# Builds Fetch Request of Attributes Exchange
ax_req = OpenID::AX::FetchRequest.new
requested_attrs = [ ['http://schema.openid.net/namePerson', 'name', true],
['http://schema.openid.net/namePerson/friendly', 'nickname'],
['http://schema.openid.net/contact/email', 'email', true],
['http://schema.openid.net/contact/web/default', 'web_default'],
['http://schema.openid.net/contact/postalCode/home', 'postal_code'],
['http://schema.openid.net/person/gender', 'gender'],
['http://schema.openid.net/birthDate', 'birthDate'],
['http://schema.openid.net/contact/country/home', 'country'],
['http://schema.openid.net/pref/language', 'language']]

requested_attrs.each {|a| ax_req.add(OpenID::AX::AttrInfo.new(a[0], a[1], a[2] || false))}
oidreq.add_extension(ax_req)
oidreq.return_to_args['did_ax'] = 'y'
pp oidreq
end


Customize a view
/path/to/rails_openid/app/views/consumer/index.rhtml

<% if flash[:ax_results]%>
<div class='alert'>
<%= flash[:ax_results] %>
</div>
<% end %>
<div id="verify-form">
<form method="get" accept-charset="UTF-8"
action='<%= url_for :action => 'start' %>'>
Identifier:
<input type="text" class="openid" name="openid_identifier" />
<input type="submit" value="Verify" /><br />
<input type="checkbox" name="immediate" id="immediate" /><label for="immediate">Use immediate mode</label><br/>
<input type="checkbox" name="use_sreg" id="use_sreg" /><label for="use_sreg">Request registration data</label><br/>
<input type="checkbox" name="use_pape" id="use_pape" /><label for="use_pape">Request phishing-resistent auth policy (PAPE)</label><br/>
<input type="checkbox" name="force_post" id="force_post" /><label for="force_post">Force the transaction to use POST by adding 2K of extra data</label><br/>
<input type="checkbox" name="use_ax" id="use_ax" /><label for="use_ax">Request registration data with AX (Attribute Exchange)</label>
</form>
</div>


ConsumerController#complete in /path/to/rails_openid/app/controllers/consumer_controller.rb

if params[:did_ax]
ax_resp = OpenID::AX::FetchResponse.from_success_response(oidresp)
pp ax_resp
end


Screenshot


We can fetch some attribtues from myOpenID, above code's output is as follows:

OpenID::Consumer::CheckIDRequest instance

#<OpenID::Consumer::CheckIDRequest:0x33543fc
@anonymous=false,
@assoc=
#<OpenID::Association:0x3354500
@assoc_type="HMAC-SHA1",
@handle="{HMAC-SHA1}{47dd30ef}{WTRsAg==}",
@issued=Sun Mar 16 14:38:35 +0000 2008,
@lifetime=1209600,
@secret="\005F6\246W\032\220\233]\002V$j\034��j�!1">,
@endpoint=
#<OpenID::OpenIDServiceEndpoint:0x33602b0
@canonical_id=nil,
@claimed_id="http://rakuto.myopenid.com/",
@display_identifier=nil,
@local_id="http://rakuto.myopenid.com/",
@server_url="http://www.myopenid.com/server",
@type_uris=
["http://specs.openid.net/auth/2.0/signon",
"http://openid.net/sreg/1.0",
"http://openid.net/extensions/sreg/1.1",
"http://schemas.openid.net/pape/policies/2007/06/phishing-resistant",
"http://openid.net/srv/ax/1.0"],
@used_yadis=true>,
@message=
#<OpenID::Message:0x3354334
@args=
{["http://openid.net/srv/ax/1.0", "type.gender"]=>
"http://schema.openid.net/person/gender",
["http://openid.net/srv/ax/1.0", "if_available"]=>
"country,web_default,language,birthDate,postal_code,nickname,gender",
["http://openid.net/srv/ax/1.0", "type.language"]=>
"http://schema.openid.net/pref/language",
["http://openid.net/srv/ax/1.0", "type.postal_code"]=>
"http://schema.openid.net/contact/postalCode/home",
["http://openid.net/srv/ax/1.0", "mode"]=>"fetch_request",
["http://openid.net/srv/ax/1.0", "type.birthDate"]=>
"http://schema.openid.net/birthDate",
["http://openid.net/srv/ax/1.0", "type.country"]=>
"http://schema.openid.net/contact/country/home",
["http://openid.net/srv/ax/1.0", "type.nickname"]=>
"http://schema.openid.net/namePerson/friendly",
["http://openid.net/srv/ax/1.0", "type.name"]=>
"http://schema.openid.net/namePerson",
["http://openid.net/srv/ax/1.0", "required"]=>"name,email",
["http://openid.net/srv/ax/1.0", "type.web_default"]=>
"http://schema.openid.net/contact/web/default",
["http://openid.net/srv/ax/1.0", "type.email"]=>
"http://schema.openid.net/contact/email"},
@namespaces=
#<OpenID::NamespaceMap:0x33542d0
@alias_to_namespace=
{"ax"=>"http://openid.net/srv/ax/1.0",
:null_namespace=>"http://specs.openid.net/auth/2.0"},
@namespace_to_alias=
{"http://specs.openid.net/auth/2.0"=>:null_namespace,
"http://openid.net/srv/ax/1.0"=>"ax"}>,
@openid_ns_uri="http://specs.openid.net/auth/2.0">,
@return_to_args={"did_ax"=>"y"}>


OpenID::Consumer::SuccessResponse instance

#<OpenID::Consumer::SuccessResponse:0x32800c0
@endpoint=
#<OpenID::OpenIDServiceEndpoint:0x32bea28
@canonical_id=nil,
@claimed_id="http://rakuto.myopenid.com/",
@display_identifier=nil,
@local_id="http://rakuto.myopenid.com/",
@server_url="http://www.myopenid.com/server",
@type_uris=
["http://specs.openid.net/auth/2.0/signon",
"http://openid.net/sreg/1.0",
"http://openid.net/extensions/sreg/1.1",
"http://schemas.openid.net/pape/policies/2007/06/phishing-resistant",
"http://openid.net/srv/ax/1.0"],
@used_yadis=true>,
@identity_url="http://rakuto.myopenid.com/",
@message=
#<OpenID::Message:0x3296f78
@args=
{["http://openid.net/srv/ax/1.0", "type.gender"]=>
"http://schema.openid.net/person/gender",
["http://specs.openid.net/auth/2.0", "sig"]=>
"5aziAIn3yMlbxq8XFaF8hKG4GCk=",
[:bare_namespace, "did_ax"]=>"y",
["http://openid.net/srv/ax/1.0", "type.language"]=>
"http://schema.openid.net/pref/language",
["http://openid.net/srv/ax/1.0", "count.gender"]=>"1",
["http://specs.openid.net/auth/2.0", "mode"]=>"id_res",
["http://openid.net/srv/ax/1.0", "mode"]=>"fetch_response",
["http://openid.net/srv/ax/1.0", "type.postal_code"]=>
"http://schema.openid.net/contact/postalCode/home",
["http://openid.net/srv/ax/1.0", "value.gender.1"]=>"M",
["http://specs.openid.net/auth/2.0", "op_endpoint"]=>
"http://www.myopenid.com/server",
["http://specs.openid.net/auth/2.0", "response_nonce"]=>
"2008-03-22T04:51:54ZT0280h",
["http://openid.net/srv/ax/1.0", "type.birthDate"]=>
"http://schema.openid.net/birthDate",
["http://openid.net/srv/ax/1.0", "value.name.1"]=>"Rakuto Furutani",
["http://openid.net/srv/ax/1.0", "count.postal_code"]=>"0",
["http://openid.net/srv/ax/1.0", "value.nickname.1"]=>"rakuto",
["http://openid.net/srv/ax/1.0", "type.country"]=>
"http://schema.openid.net/contact/country/home",
["http://openid.net/srv/ax/1.0", "count.name"]=>"1",
["http://openid.net/srv/ax/1.0", "count.web_default"]=>"1",
["http://openid.net/srv/ax/1.0", "type.nickname"]=>
"http://schema.openid.net/namePerson/friendly",
["http://specs.openid.net/auth/2.0", "return_to"]=>
"http://localhost:3001/consumer/complete?did_ax=y",
["http://specs.openid.net/auth/2.0", "assoc_handle"]=>
"{HMAC-SHA1}{47dd30ef}{WTRsAg==}",
["http://openid.net/srv/ax/1.0", "count.email"]=>"0",
["http://openid.net/srv/ax/1.0", "type.name"]=>
"http://schema.openid.net/namePerson",
["http://openid.net/srv/ax/1.0", "count.nickname"]=>"1",
["http://openid.net/srv/ax/1.0", "count.country"]=>"1",
["http://specs.openid.net/auth/2.0", "identity"]=>
"http://rakuto.myopenid.com/",
["http://specs.openid.net/auth/2.0", "signed"]=>
"assoc_handle,ax.count.birthDate,ax.count.country,ax.count.email,ax.count.gender,ax.count.language,ax.count.name,ax.count.nickname,ax.count.postal_code,ax.count.web_default,ax.mode,ax.type.birthDate,ax.type.country,ax.type.email,ax.type.gender,ax.type.language,ax.type.name,ax.type.nickname,ax.type.postal_code,ax.type.web_default,ax.value.birthDate.1,ax.value.country.1,ax.value.gender.1,ax.value.language.1,ax.value.name.1,ax.value.nickname.1,ax.value.web_default.1,claimed_id,identity,mode,ns,ns.ax,op_endpoint,response_nonce,return_to,signed",
["http://openid.net/srv/ax/1.0", "count.language"]=>"1",
["http://openid.net/srv/ax/1.0", "value.language.1"]=>"JA",
["http://openid.net/srv/ax/1.0", "value.web_default.1"]=>
"http://raku.to/",
["http://openid.net/srv/ax/1.0", "value.birthDate.1"]=>"1985-03-12",
["http://openid.net/srv/ax/1.0", "type.web_default"]=>
"http://schema.openid.net/contact/web/default",
["http://openid.net/srv/ax/1.0", "type.email"]=>
"http://schema.openid.net/contact/email",
["http://openid.net/srv/ax/1.0", "value.country.1"]=>"JP",
["http://specs.openid.net/auth/2.0", "claimed_id"]=>
"http://rakuto.myopenid.com/",
["http://openid.net/srv/ax/1.0", "count.birthDate"]=>"1"},
@namespaces=
#<OpenID::NamespaceMap:0x329680c
@alias_to_namespace=
{"ax"=>"http://openid.net/srv/ax/1.0",
:null_namespace=>"http://specs.openid.net/auth/2.0"},
@namespace_to_alias=
{"http://specs.openid.net/auth/2.0"=>:null_namespace,
"http://openid.net/srv/ax/1.0"=>"ax"}>,
@openid_ns_uri="http://specs.openid.net/auth/2.0">,
@signed_fields=
[
"openid.assoc_handle",
"openid.ax.count.birthDate",
"openid.ax.count.country",
"openid.ax.count.email",
"openid.ax.count.gender",
"openid.ax.count.language",
"openid.ax.count.name",
"openid.ax.count.nickname",
"openid.ax.count.postal_code",
"openid.ax.count.web_default",
"openid.ax.mode",
"openid.ax.type.birthDate",
"openid.ax.type.country",
"openid.ax.type.email",
"openid.ax.type.gender",
"openid.ax.type.language",
"openid.ax.type.name",
"openid.ax.type.nickname",
"openid.ax.type.postal_code",
"openid.ax.type.web_default",
"openid.ax.value.birthDate.1",
"openid.ax.value.country.1",
"openid.ax.value.gender.1",
"openid.ax.value.language.1",
"openid.ax.value.name.1",
"openid.ax.value.nickname.1",
"openid.ax.value.web_default.1",
"openid.claimed_id",
"openid.identity",
"openid.mode",
"openid.ns",
"openid.ns.ax",
"openid.op_endpoint",
"openid.response_nonce",
"openid.return_to",
"openid.signed"]>


Extracted attributes from response - OpenID::AX::FetchResponse instance

#<OpenID::AX::FetchResponse:0x3254a4c
@data=
{"http://schema.openid.net/namePerson"=>["Rakuto Furutani"],
"http://schema.openid.net/contact/country/home"=>["JP"],
"http://schema.openid.net/contact/web/default"=>["http://raku.to/"],
"http://schema.openid.net/pref/language"=>["JA"],
"http://schema.openid.net/contact/email"=>[],
"http://schema.openid.net/birthDate"=>["1985-03-12"],
"http://schema.openid.net/contact/postalCode/home"=>[],
"http://schema.openid.net/namePerson/friendly"=>["rakuto"],
"http://schema.openid.net/person/gender"=>["M"]},
@mode="fetch_response",
@ns_alias="ax",
@ns_uri="http://openid.net/srv/ax/1.0",
@update_url=nil>

Conclusion about myOpenID
  • Supports only some attributes that can be exchanged with AX.
  • Doesn't support openid.ax.update_url yet.
  • Doesn't support Type URI described in axschema, you should specify Type URI with "http://schema.openid.net/" namespace.