Permalink
Browse files

initial import

  • Loading branch information...
0 parents commit 6b315f45e5cec6caab8f17287342523aaaf212df @tomyhero committed May 18, 2011
Showing with 178 additions and 0 deletions.
  1. +2 −0 .shipit
  2. +4 −0 Changes
  3. +19 −0 MANIFEST.SKIP
  4. +13 −0 Makefile.PL
  5. +27 −0 README
  6. +83 −0 lib/Aplon/Model/OAuth2/Client/WebServer.pm
  7. +26 −0 lib/Aplon/Model/OAuth2/Client/WebServer/Facebook.pm
  8. +4 −0 t/00_compile.t
@@ -0,0 +1,2 @@
+steps = FindVersion, ChangeVersion, CheckChangeLog, DistTest, Commit, Tag, MakeDist, UploadCPAN
+svk.tagpattern = release-%v
@@ -0,0 +1,4 @@
+Revision history for Perl extension Aplon::Model::OAuth2::Client::WebServer
+
+0.01 Wed May 18 15:26:23 2011
+ - original version
@@ -0,0 +1,19 @@
+\bRCS\b
+\bCVS\b
+^MANIFEST\.
+^Makefile$
+~$
+^#
+\.old$
+^blib/
+^pm_to_blib
+^MakeMaker-\d
+\.gz$
+\.cvsignore
+^t/9\d_.*\.t
+^t/perlcritic
+^tools/
+\.svn/
+^[^/]+\.yaml$
+^[^/]+\.pl$
+^\.shipit$
@@ -0,0 +1,13 @@
+use inc::Module::Install;
+name 'Aplon-Model-OAuth2-Client-WebServer';
+all_from 'lib/Aplon/Model/OAuth2/Client/WebServer.pm';
+
+requires 'Aplon';
+requires 'OAuth::Lite2';
+
+tests 't/*.t';
+
+build_requires 'Test::More';
+use_test_base;
+auto_include;
+WriteAll;
27 README
@@ -0,0 +1,27 @@
+This is Perl module Aplon::Model::OAuth2::Client::WebServer.
+
+INSTALLATION
+
+Aplon::Model::OAuth2::Client::WebServer installation is straightforward. If your CPAN shell is set up,
+you should just be able to do
+
+ % cpan Aplon::Model::OAuth2::Client::WebServer
+
+Download it, unpack it, then build it as per the usual:
+
+ % perl Makefile.PL
+ % make && make test
+
+Then install it:
+
+ % make install
+
+DOCUMENTATION
+
+Aplon::Model::OAuth2::Client::WebServer documentation is available as in POD. So you can do:
+
+ % perldoc Aplon::Model::OAuth2::Client::WebServer
+
+to read the documentation online with your favorite pager.
+
+polocky
@@ -0,0 +1,83 @@
+package Aplon::Model::OAuth2::Client::WebServer;
+use strict;
+use Mouse;
+extends 'Aplon';
+with 'Aplon::Validator::Simple';
+use OAuth::Lite2::Client::WebServer;
+
+
+our $VERSION = '0.01';
+
+# for instance
+has 'id' => ( is => 'rw', required => 1);
+has 'secret' => ( is => 'rw', required => 1);
+has 'authorize_uri' => ( is => 'rw', required => 1);
+has 'access_token_uri' => ( is => 'rw', required => 1);
+
+
+has 'redirect_uri' => (is => 'rw', required => 1);
+has 'scope' => (is => 'rw', default => '');
+has 'state' => (is => 'rw', default => '');
+has 'immediate' => (is => 'rw', default => '');
+has 'extra' => ( is => 'rw', default => sub {+{}} );
+
+has 'client' => (
+ is => 'rw',
+ lazy_build => 1,
+);
+
+sub _build_client {
+ my $self = shift;
+ my $client = OAuth::Lite2::Client::WebServer->new(
+ id => $self->id,
+ secret => $self->secret,
+ authorize_uri => $self->authorize_uri,
+ access_token_uri => $self->access_token_uri,
+ );
+ return $client;
+}
+
+sub start_authorize {
+ my $self = shift;
+ my $redirect_url = $self->client->uri_to_redirect(
+ redirect_uri => $self->redirect_uri,
+ scope => $self->scope,
+ state => $self->state,
+ immediate => $self->immediate,
+ extra => $self->extra,
+ );
+ return $redirect_url;
+}
+
+sub callback {
+ my $self = shift;
+ my $args = shift || {};
+ my $code = $args->{code} or $self->abort_with({
+ code => "OAUTH2_FAILED" ,
+ missing => ['code'],
+ });
+ my $client = $self->client;
+ my $access_token = $client->get_access_token(
+ code => $code,
+ redirect_uri => $self->redirect_uri,
+ ) or $self->abort_with({
+ code => 'OAUTH2_FAILED',
+ custom_invalid => ['get_access_token_faild' ],
+ message => $client->errstr }
+ );
+
+ return $self->do_complate( $access_token );
+}
+
+sub do_complate {
+ my $self = shift;
+ my $access_token = shift ;
+ die 'do_complate() is ABSTRACT method';
+}
+
+
+__PACKAGE__->meta->make_immutable();
+
+no Mouse;
+
+1;
@@ -0,0 +1,26 @@
+package Aplon::Model::OAuth2::Client::WebServer::Facebook;
+use strict;
+use Mouse;
+extends 'Aplon::Model::OAuth2::Client::WebServer';
+
+has '+authorize_uri' => ( default => 'https://graph.facebook.com/oauth/authorize' );
+has '+access_token_uri' => ( default => 'https://graph.facebook.com/oauth/access_token' );
+has 'display' => ( is => 'rw', default => 'page' );
+
+has 'extra' => (
+ is => 'rw',
+ lazy_build => 1,
+);
+
+sub _build_extra {
+ my $self = shift;
+ my $hash = {};
+ $hash->{display} = $self->display;
+ return $hash;
+}
+
+__PACKAGE__->meta->make_immutable();
+
+no Mouse;
+
+1;
@@ -0,0 +1,4 @@
+use strict;
+use Test::More tests => 1;
+
+BEGIN { use_ok 'Aplon::Model::OAuth2::Client::WebServer' }

0 comments on commit 6b315f4

Please sign in to comment.