Skip Menu |

This queue is for tickets about the WWW-LinkedIn CPAN distribution.

Report information
The Basics
Id: 79283
Status: open
Priority: 0/
Queue: WWW-LinkedIn

People
Owner: Nobody in particular
Requestors: scott [...] dearie.me.uk
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: 0.004
Fixed in: (no value)



Subject: Allow optional 'scope' parameter to get_request_token
I needed to use the new permissions[1] functionality from LinkedIn in conjunction with WWW::LinkedIn, the attached (trivial) patch implements it. It would be cool if this (or something similar) was rolled into the CPAN distro. Many thanks, Scott [1] https://developer.linkedin.com/blog/making-it-easier-you-develop- linkedin
Subject: add_scope_param.patch
diff --git a/lib/WWW/LinkedIn.pm b/lib/WWW/LinkedIn.pm index e66671a..af4339a 100644 --- a/lib/WWW/LinkedIn.pm +++ b/lib/WWW/LinkedIn.pm @@ -47,10 +47,12 @@ sub get_request_token my $nonce = md5_hex(time() * rand()); my $timestamp = time(); + my $request_url = 'https://api.linkedin.com/uas/oauth/requestToken'; + $request_url .= '?scope=' . $args{scope} if $args{scope}; my $request = Net::OAuth->request("request token")->new( consumer_key => $s->consumer_key, consumer_secret => $s->consumer_secret, - request_url => 'https://api.linkedin.com/uas/oauth/requestToken', + request_url => $request_url, request_method => 'POST', signature_method => 'HMAC-SHA1', timestamp => $timestamp, @@ -58,6 +60,7 @@ sub get_request_token callback => $args{callback}, ); $request->sign; + my $res = LWP::UserAgent->new()->request(POST $request->to_url); my ($token) = $res->content =~ m{token\=([^&]+)} or confess "LinkedIn's API did not return a request token. Instead, it returned this:\n" . $res->as_string;
From: korey.openid [...] gmail.com
I am also looking at using LinkedIn with additional scopes. The Net::OAuth already has provision for extra parameters to passed. A cleaner implementation could be: diff --git a/lib/WWW/LinkedIn.pm b/lib/WWW/LinkedIn.pm index e66671a..1663047 100644 --- a/lib/WWW/LinkedIn.pm +++ b/lib/WWW/LinkedIn.pm @@ -56,6 +56,9 @@ sub get_request_token timestamp => $timestamp, nonce => $nonce, callback => $args{callback}, + extra_params => { + ($args{scope} ? ( scope => $args{scope} ) : ()), + }, ); $request->sign; my $res = LWP::UserAgent->new()->request(POST $request->to_url);
Thanks for the snippets. Note that when this code is used, you need to replace the '+' sign in usage examples with a space as follows: my $token = $li->get_request_token( callback => $callback, scope => 'r_basicprofile r_emailaddress', );