Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable hostname verification #10

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 60 additions & 8 deletions lib/Facebook/Graph.pm
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ has access_token => (
predicate => 'has_access_token',
);

has lwp_opts => (
is => 'rw',
predicate => 'has_lwp_opts',
default => sub { { } },
);


sub parse_signed_request {
my ($self, $signed_request) = @_;
Expand Down Expand Up @@ -64,6 +70,7 @@ sub request_access_token {
postback => $self->postback,
secret => $self->secret,
app_id => $self->app_id,
lwp_opts => $self->lwp_opts,
)->request;
$self->access_token($token->token);
return $token;
Expand All @@ -74,13 +81,14 @@ sub convert_sessions {
return Facebook::Graph::Session->new(
secret => $self->secret,
app_id => $self->app_id,
lwp_opts => $self->lwp_opts,
sessions => $sessions,
)
->request
->as_hashref;
}

sub authorize {
sub authorize {
my ($self) = @_;
return Facebook::Graph::Authorize->new(
app_id => $self->app_id,
Expand All @@ -102,6 +110,9 @@ sub query {
if ($self->has_secret) {
$params{secret} = $self->secret;
}
if ($self->has_lwp_opts) {
$params{lwp_opts} = $self->lwp_opts;
}
return Facebook::Graph::Query->new(%params);
}

Expand All @@ -122,6 +133,9 @@ sub add_post {
if ($self->has_secret) {
$params{secret} = $self->secret;
}
if ($self->has_lwp_opts) {
$params{lwp_opts} = $self->lwp_opts;
}
return Facebook::Graph::Publish::Post->new( %params );
}

Expand All @@ -137,6 +151,9 @@ sub add_checkin {
if ($self->has_secret) {
$params{secret} = $self->secret;
}
if ($self->has_lwp_opts) {
$params{lwp_opts} = $self->lwp_opts;
}
return Facebook::Graph::Publish::Checkin->new( %params );
}

Expand All @@ -151,6 +168,9 @@ sub add_like {
if ($self->has_secret) {
$params{secret} = $self->secret;
}
if ($self->has_lwp_opts) {
$params{lwp_opts} = $self->lwp_opts;
}
return Facebook::Graph::Publish::Like->new( %params );
}

Expand All @@ -165,6 +185,9 @@ sub add_comment {
if ($self->has_secret) {
$params{secret} = $self->secret;
}
if ($self->has_lwp_opts) {
$params{lwp_opts} = $self->lwp_opts;
}
return Facebook::Graph::Publish::Comment->new( %params );
}

Expand All @@ -177,6 +200,9 @@ sub add_note {
if ($self->has_secret) {
$params{secret} = $self->secret;
}
if ($self->has_lwp_opts) {
$params{lwp_opts} = $self->lwp_opts;
}
return Facebook::Graph::Publish::Note->new( %params );
}

Expand All @@ -189,6 +215,9 @@ sub add_link {
if ($self->has_secret) {
$params{secret} = $self->secret;
}
if ($self->has_lwp_opts) {
$params{lwp_opts} = $self->lwp_opts;
}
return Facebook::Graph::Publish::Link->new( %params );
}

Expand All @@ -204,6 +233,9 @@ sub add_event {
if ($self->has_secret) {
$params{secret} = $self->secret;
}
if ($self->has_lwp_opts) {
$params{lwp_opts} = $self->lwp_opts;
}
return Facebook::Graph::Publish::Event->new( %params );
}

Expand All @@ -218,6 +250,9 @@ sub rsvp_maybe {
if ($self->has_secret) {
$params{secret} = $self->secret;
}
if ($self->has_lwp_opts) {
$params{lwp_opts} = $self->lwp_opts;
}
return Facebook::Graph::Publish::RSVPMaybe->new( %params );
}

Expand All @@ -232,6 +267,9 @@ sub rsvp_attending {
if ($self->has_secret) {
$params{secret} = $self->secret;
}
if ($self->has_lwp_opts) {
$params{lwp_opts} = $self->lwp_opts;
}
return Facebook::Graph::Publish::RSVPAttending->new( %params );
}

Expand All @@ -246,6 +284,9 @@ sub rsvp_declined {
if ($self->has_secret) {
$params{secret} = $self->secret;
}
if ($self->has_lwp_opts) {
$params{lwp_opts} = $self->lwp_opts;
}
return Facebook::Graph::Publish::RSVPDeclined->new( %params );
}

Expand All @@ -263,7 +304,7 @@ Facebook::Graph - A fast and easy way to integrate your apps with Facebook.
my $fb = Facebook::Graph->new;
my $sarah_bownds = $fb->fetch('sarahbownds');
my $perl_page = $fb->fetch('16665510298');

Or better yet:

my $sarah_bownds = $fb->query
Expand All @@ -272,16 +313,16 @@ Or better yet:
->select_fields(qw( id name picture ))
->request
->as_hashref;

my $sarahs_picture_uri = $fb->picture('sarahbownds')->get_large->uri_as_string;

Or fetching a response from a URI you already have:

my $response = $fb->query
->request('https://graph.facebook.com/btaylor')
->as_hashref;


=head2 Building A Privileged App

my $fb = Facebook::Graph->new(
Expand All @@ -303,11 +344,11 @@ Handle the Facebook authorization code postback:

my $q = Plack::Request->new($env);
$fb->request_access_token($q->query_param('code'));

Or if you already had the access token:

$fb->access_token($token);

Get some info:

my $user = $fb->fetch('me');
Expand Down Expand Up @@ -353,6 +394,17 @@ The URI that Facebook should post your authorization code back to. Required if y

B<NOTE:> It must be a sub URI of the URI that you put in the Application Settings > Connect > Connect URL field of your application's profile on Facebook.

=item lwp_opts

A hash ref for the options to pass to LWP::UserAgent when one is created. This is the hash that one would give to LWP::UserAgent->new(). For example:

my $fb = Facebook::Graph->new(
app_id => 'your_id',
secret => 'your_app_secret',
lwp_opts => { ssl_opts => { verify_hostname => 0 } }
);


=back


Expand Down Expand Up @@ -380,7 +432,7 @@ Creates a L<Facebook::Graph::Query> object, which can be used to fetch and searc
Returns a hash reference of an object from facebook. A quick way to grab an object from Facebook. These two statements are identical:

my $sarah = $fb->fetch('sarahbownds');

my $sarah = $fb->query->find('sarahbownds')->request->as_hashref;

=head3 id
Expand Down
8 changes: 7 additions & 1 deletion lib/Facebook/Graph/AccessToken.pm
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ has code => (
required=> 1,
);

has lwp_opts => (
is => 'rw',
predicate => 'has_lwp_opts',
default => sub { { } },
);

sub uri_as_string {
my ($self) = @_;
my $uri = $self->uri;
Expand All @@ -40,7 +46,7 @@ sub uri_as_string {

sub request {
my ($self) = @_;
my $response = LWP::UserAgent->new->get($self->uri_as_string);
my $response = LWP::UserAgent->new(%{ $self->lwp_opts })->get($self->uri_as_string);
return Facebook::Graph::AccessToken::Response->new(response => $response);
}

Expand Down
10 changes: 8 additions & 2 deletions lib/Facebook/Graph/Publish.pm
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ has object_name => (
default => 'me',
);

has lwp_opts => (
is => 'rw',
predicate => 'has_lwp_opts',
default => sub { { } },
);

sub to {
my ($self, $object_name) = @_;
$self->object_name($object_name);
Expand All @@ -41,7 +47,7 @@ sub publish {
my ($self) = @_;
my $uri = $self->uri;
$uri->path($self->object_name.$self->object_path);
my $response = LWP::UserAgent->new->post($uri, $self->get_post_params);
my $response = LWP::UserAgent->new(%{ $self->lwp_opts })->post($uri, $self->get_post_params);
my %params = (response => $response);
if ($self->has_secret) {
$params{secret} = $self->secret;
Expand All @@ -59,7 +65,7 @@ Facebook::Graph::Publish - A base class for publishing various things to faceboo

=head1 DESCRIPTION

This module shouldn't be used by you directly for any purpose.
This module shouldn't be used by you directly for any purpose.

=head1 LEGAL

Expand Down
21 changes: 14 additions & 7 deletions lib/Facebook/Graph/Query.pm
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,18 @@ has since => (
predicate => 'has_since',
);

has lwp_opts => (
is => 'rw',
predicate => 'has_lwp_opts',
default => sub { { } },
);



sub limit_results {
my ($self, $limit) = @_;
$self->limit($limit);
return $self;
return $self;
}

sub find {
Expand Down Expand Up @@ -105,7 +112,7 @@ sub from {
sub offset_results {
my ($self, $offset) = @_;
$self->offset($offset);
return $self;
return $self;
}

sub include_metadata {
Expand Down Expand Up @@ -181,7 +188,7 @@ sub uri_as_string {
sub request {
my ($self, $uri) = @_;
$uri ||= $self->uri_as_string;
my $response = LWP::UserAgent->new->get($uri);
my $response = LWP::UserAgent->new(%{ $self->lwp_opts })->get($uri);
my %params = (response => $response);
if ($self->has_secret) {
$params{secret} = $self->secret;
Expand All @@ -200,12 +207,12 @@ Facebook::Graph::Query - Simple and fast searching and fetching of Facebook data
=head1 SYNOPSIS

my $fb = Facebook::Graph->new;

my $perl_page = $fb->find('16665510298')
->include_metadata
->request
->as_hashref;

my $sarah_bownds = $fb->find('sarahbownds')
->select_fields(qw(id name))
->request
Expand Down Expand Up @@ -239,7 +246,7 @@ This module presents a programatic approach to building the queries necessary to
->limit_results(25)
->request
->as_hashref;

The above query, if you were read it like text, says: "Give me the user ids and full names of all users named Dave that have been created since yesterday, and limit the result set to the first 25."


Expand Down Expand Up @@ -299,7 +306,7 @@ All groups.

=head2 search ( query, context )

Perform a keyword search on a group of items.
Perform a keyword search on a group of items.

If you prefer not to search by keyword see the C<from> method.

Expand Down
8 changes: 7 additions & 1 deletion lib/Facebook/Graph/Session.pm
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ has sessions => (
required=> 1,
);

has lwp_opts => (
is => 'rw',
predicate => 'has_lwp_opts',
default => sub { { } },
);

sub uri_as_string {
my ($self) = @_;
my $uri = $self->uri;
Expand All @@ -35,7 +41,7 @@ sub uri_as_string {

sub request {
my ($self) = @_;
my $response = LWP::UserAgent->new->get($self->uri_as_string);
my $response = LWP::UserAgent->new(%{ $self->lwp_opts })->get($self->uri_as_string);
return Facebook::Graph::Response->new(response => $response);
}

Expand Down