source: perl/modules/Facebook/lib/Facebook/Graph/Authorize.pm @ 7777ac2

release-1.9
Last change on this file since 7777ac2 was 2a42248, checked in by Edward Z. Yang <ezyang@mit.edu>, 10 years ago
Add vanilla Facebook::Graph. Signed-off-by: Edward Z. Yang <ezyang@mit.edu>
  • Property mode set to 100644
File size: 2.8 KB
Line 
1package Facebook::Graph::Authorize;
2BEGIN {
3  $Facebook::Graph::Authorize::VERSION = '1.0300';
4}
5
6use Any::Moose;
7with 'Facebook::Graph::Role::Uri';
8
9has app_id => (
10    is      => 'ro',
11    required=> 1,
12);
13
14has postback => (
15    is      => 'ro',
16    required=> 1,
17);
18
19has permissions => (
20    is          => 'rw',
21    lazy        => 1,
22    predicate   => 'has_permissions',
23    default     => sub { [] },
24);
25
26has display => (
27    is      => 'rw',
28    default => 'page',
29);
30
31sub extend_permissions {
32    my ($self, @permissions) = @_;
33    push @{$self->permissions}, @permissions;
34    return $self;
35}
36
37sub set_display {
38    my ($self, $display) = @_;
39    $self->display($display);
40    return $self;
41}
42
43sub 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
59no Any::Moose;
60__PACKAGE__->meta->make_immutable;
61
62
63=head1 NAME
64
65Facebook::Graph::Authorize - Authorizing an app with Facebook
66
67
68=head1 VERSION
69
70version 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
87Get 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
93Ask 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
97An 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
102Sets the display type for the authorization screen that a user will see.
103
104=head3 type
105
106Defaults 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
111Returns a URI string to redirect the user back to Facebook.
112
113
114
115=head1 LEGAL
116
117Facebook::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
Note: See TracBrowser for help on using the repository browser.