[2a42248] | 1 | package Facebook::Graph::Authorize; |
---|
| 2 | BEGIN { |
---|
| 3 | $Facebook::Graph::Authorize::VERSION = '1.0300'; |
---|
| 4 | } |
---|
| 5 | |
---|
| 6 | use Any::Moose; |
---|
| 7 | with 'Facebook::Graph::Role::Uri'; |
---|
| 8 | |
---|
| 9 | has app_id => ( |
---|
| 10 | is => 'ro', |
---|
| 11 | required=> 1, |
---|
| 12 | ); |
---|
| 13 | |
---|
| 14 | has postback => ( |
---|
| 15 | is => 'ro', |
---|
| 16 | required=> 1, |
---|
| 17 | ); |
---|
| 18 | |
---|
| 19 | has permissions => ( |
---|
| 20 | is => 'rw', |
---|
| 21 | lazy => 1, |
---|
| 22 | predicate => 'has_permissions', |
---|
| 23 | default => sub { [] }, |
---|
| 24 | ); |
---|
| 25 | |
---|
| 26 | has display => ( |
---|
| 27 | is => 'rw', |
---|
| 28 | default => 'page', |
---|
| 29 | ); |
---|
| 30 | |
---|
| 31 | sub extend_permissions { |
---|
| 32 | my ($self, @permissions) = @_; |
---|
| 33 | push @{$self->permissions}, @permissions; |
---|
| 34 | return $self; |
---|
| 35 | } |
---|
| 36 | |
---|
| 37 | sub set_display { |
---|
| 38 | my ($self, $display) = @_; |
---|
| 39 | $self->display($display); |
---|
| 40 | return $self; |
---|
| 41 | } |
---|
| 42 | |
---|
| 43 | sub uri_as_string { |
---|
| 44 | my ($self) = @_; |
---|
| 45 | my $uri = $self->uri; |
---|
| 46 | $uri->path('oauth/authorize'); |
---|
| 47 | my %query = ( |
---|
| 48 | client_id => $self->app_id, |
---|
| 49 | redirect_uri => $self->postback, |
---|
| 50 | display => $self->display, |
---|
| 51 | ); |
---|
| 52 | if ($self->has_permissions) { |
---|
| 53 | $query{scope} = join(',', @{$self->permissions}); |
---|
| 54 | } |
---|
| 55 | $uri->query_form(%query); |
---|
| 56 | return $uri->as_string; |
---|
| 57 | } |
---|
| 58 | |
---|
| 59 | no Any::Moose; |
---|
| 60 | __PACKAGE__->meta->make_immutable; |
---|
| 61 | |
---|
| 62 | |
---|
| 63 | =head1 NAME |
---|
| 64 | |
---|
| 65 | Facebook::Graph::Authorize - Authorizing an app with Facebook |
---|
| 66 | |
---|
| 67 | |
---|
| 68 | =head1 VERSION |
---|
| 69 | |
---|
| 70 | version 1.0300 |
---|
| 71 | |
---|
| 72 | =head1 SYNOPSIS |
---|
| 73 | |
---|
| 74 | my $fb = Facebook::Graph->new( |
---|
| 75 | secret => $facebook_application_secret, |
---|
| 76 | app_id => $facebook_application_id, |
---|
| 77 | postback => 'https://www.yourapplication.com/facebook/postback', |
---|
| 78 | ); |
---|
| 79 | |
---|
| 80 | my $uri = $fb->authorize |
---|
| 81 | ->extend_permissions(qw( email publish_stream )) |
---|
| 82 | ->set_display('popup') |
---|
| 83 | ->uri_as_string; |
---|
| 84 | |
---|
| 85 | =head1 DESCRIPTION |
---|
| 86 | |
---|
| 87 | Get an authorization code from Facebook so that you can request an access token to make privileged requests. The result of this package is to give you a URI to redirect a user to Facebook so they can log in, and approve whatever permissions you are requesting. |
---|
| 88 | |
---|
| 89 | =head1 METHODS |
---|
| 90 | |
---|
| 91 | =head2 extend_permissions ( permissions ) |
---|
| 92 | |
---|
| 93 | Ask for extra permissions for your app. By default, if you do not request extended permissions your app will have access to only general information that any Facebook user would have. Returns a reference to self for method chaining. |
---|
| 94 | |
---|
| 95 | =head3 permissions |
---|
| 96 | |
---|
| 97 | An array of permissions. See L<http://developers.facebook.com/docs/authentication/permissions> for more information about what's available. |
---|
| 98 | |
---|
| 99 | |
---|
| 100 | =head2 set_display ( type ) |
---|
| 101 | |
---|
| 102 | Sets the display type for the authorization screen that a user will see. |
---|
| 103 | |
---|
| 104 | =head3 type |
---|
| 105 | |
---|
| 106 | Defaults to C<page>. Valid types are C<page>, C<popup>, C<wap>, and C<touch>. See B<Dialog Form Factors> in L<http://developers.facebook.com/docs/authentication/> for details. |
---|
| 107 | |
---|
| 108 | |
---|
| 109 | =head2 uri_as_string ( ) |
---|
| 110 | |
---|
| 111 | Returns a URI string to redirect the user back to Facebook. |
---|
| 112 | |
---|
| 113 | |
---|
| 114 | |
---|
| 115 | =head1 LEGAL |
---|
| 116 | |
---|
| 117 | Facebook::Graph is Copyright 2010 Plain Black Corporation (L<http://www.plainblack.com>) and is licensed under the same terms as Perl itself. |
---|
| 118 | |
---|
| 119 | =cut |
---|