Net-OAuth
A Perl wrapper for the OAuth 1.0 specification.
INSTALLATION
$ cpan
cpan> install Net::OAuth
WEB SERVER EXAMPLE (Dancer)
# This example is simplified for illustrative purposes, see the complete code in /demo
# Note that client_id is the Consumer Key and client_secret is the Consumer Secret
use Dancer;
use Net::OAuth::Client;
sub client {
Net::OAuth::Client->new(
config->{client_id},
config->{client_secret},
request_token_path => '/accounts/OAuthGetRequestToken?scope=https%3A%2F%2Fwww.google.com%2Fm8%2Ffeeds%2F',
authorize_path => '/accounts/OAuthAuthorizeToken',
access_token_path => '/accounts/OAuthGetAccessToken',
callback => uri_for("/auth/google/callback"),
session => \&session,
);
}
# Send user to authorize with service provider
get '/auth/google' => sub {
redirect client->authorize_url;
};
# User has returned with token and verifier appended to the URL.
get '/auth/google/callback' => sub {
# Use the auth code to fetch the access token
my $access_token = client->get_access_token(params->{oauth_token}, params->{oauth_verifier});
# Use the access token to fetch a protected resource
my $response = $access_token->get('/m8/feeds/contacts/default/full');
# Do something with said resource...
if ($response->is_success) {
return "Yay, it worked: " . $response->decoded_content;
}
else {
return "Error: " . $response->status_line;
}
};
dance;
AUTHOR
Originally by Keith Grennan <kgrennan@cpan.org>
Currently maintained by Robert Rothenberg <rrwo@cpan.org>
LICENSE AND COPYRIGHT
Copyright 2007-2012, 2024-2025 Keith Grennan
This program is free software; you can redistribute it and/or modify it
under the terms of either: the GNU General Public License as published
by the Free Software Foundation; or the Artistic License.