TypeKey認証をCatalystに組み込む
はてな認証APIをCatalystに組み込む - ヒルズで働く@robarioの技ログ
をちょっと修正して、TypeKey認証にしてみます。
まずhttps://www.typekey.com/t/typekey/にログインして「Your Weblog Preferences(コメント登録するウェブログの指定)」に「http://localhost:3000/」を指定しておきます。ドメイン名さえ合っていればいいっぽいです。はてな認証APIと違い、コールバックURIはアプリケーション側で指定します。
lib/MyApp.pm
Authentication::Credential::Hatena
を
Authentication::Credential::TypeKey
に変更。
myapp.yml
authentication: hatena: api_key: ***YOUR API_KEY*** secret: ***YOUR SECRET***
を
authentication: typekey: token: ***YOUR TOKEN***
に変更。
lib/MyApp/Controller/Root.pm
sub login : Local { my ( $self, $c ) = @_; $c->res->redirect( $c->authenticate_hatena_url ); }
を
sub login : Local { my ( $self, $c ) = @_; use URI; my $uri = URI->new('https://www.typekey.com/t/typekey/login'); $uri->query_form( v => '1.1', need_email => 0, t => $c->config->{authentication}->{typekey}->{token}, _return => $c->uri_for('/auth_typekey'), ); $c->res->redirect( $uri->as_string ); }
に変更。
sub auth_hatena : Local { my ( $self, $c ) = @_; if ( $c->authenticate_hatena ) { # login success } else { # login failed } $c->res->redirect( $c->uri_for('/') ); }
を
sub auth_typekey : Local { my ( $self, $c ) = @_; if ( $c->authenticate_typekey ) { # login success } else { # login failed } $c->res->redirect( $c->uri_for('/') ); }
に変更。
実行結果はほとんど同じなので省略。
TypeKeyもあっという間でしたね!