Skip to content

Loading…

Disable hostname verification #10

Closed
wants to merge 2 commits into from

3 participants

@posniewski

Changes the default ssl_opts to set verify_hostname to 0.

With LWP 6.02 (and other newish LWPs, I think) errors such as these occur during the test phase of the module install:

Could not execute request (https://graph.facebook.com/sarahbownds): Can't connect to graph.facebook.com:443 (certificate verify failed) at /root/.cpan/build/Facebook-Graph-1.0300-3d6YQe/blib/lib/Facebook/Graph/Response.pm line 39

Changing the ssl_opts to not check the hostname resolves this error.

@jjn1056

The basic approach seems fine, although now that I look through all this I wonder if the verify off bit should be controllable... Like I think for prod I'd probably want it on, but for installation tests and my local tests I'd need it off. Maybe a dev mode option or %ENV var or something? We probably need the maintainer to weigh in on that.

@posniewski posniewski Added the lwp_opts attribute to Facebook::Graph and children. This ca…
…n be used to set the options set whenever a LWP::UserAgent is created.
5c44df9
@posniewski

Good point, jjn. This update adds a config attribute to Facebook::Graph->new which lets you set the hash given 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 } }
);

These options are inherited by the subobjects of Graph as well.

I did not fix the tests so that they verify_hostname is off by default.

@rizen
Owner

Sorry it took me so long to review this change. It's completely unnecessary. You can pass in your own custom configured LWP::UserAgent object as a parameter to Facebook::Graph->new(). You've always been able to do this, but I've officially documented it as part of version 1.0400.

@rizen rizen closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 10, 2011
  1. @posniewski
Commits on May 11, 2011
  1. @posniewski

    Added the lwp_opts attribute to Facebook::Graph and children. This ca…

    posniewski committed
    …n be used to set the options set whenever a LWP::UserAgent is created.
View
68 lib/Facebook/Graph.pm
@@ -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) = @_;
@@ -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;
@@ -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,
@@ -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);
}
@@ -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 );
}
@@ -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 );
}
@@ -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 );
}
@@ -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 );
}
@@ -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 );
}
@@ -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 );
}
@@ -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 );
}
@@ -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 );
}
@@ -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 );
}
@@ -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 );
}
@@ -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
@@ -272,7 +313,7 @@ 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:
@@ -280,8 +321,8 @@ 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(
@@ -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');
@@ -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
@@ -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
View
8 lib/Facebook/Graph/AccessToken.pm
@@ -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;
@@ -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);
}
View
10 lib/Facebook/Graph/Publish.pm
@@ -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);
@@ -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;
@@ -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
View
21 lib/Facebook/Graph/Query.pm
@@ -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 {
@@ -105,7 +112,7 @@ sub from {
sub offset_results {
my ($self, $offset) = @_;
$self->offset($offset);
- return $self;
+ return $self;
}
sub include_metadata {
@@ -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;
@@ -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
@@ -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."
@@ -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.
View
8 lib/Facebook/Graph/Session.pm
@@ -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;
@@ -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);
}
Something went wrong with that request. Please try again.