forked from robin13/Net-OAuth2
-
Notifications
You must be signed in to change notification settings - Fork 3
OAuth 2.0 for Perl
nikopol/Net-OAuth2
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
Net-OAuth2
A Perl wrapper for the OAuth 2.0 specification. This is a work in progress, being built first to work with existing OAuth 2.0 endpoints (37 Signals, Facebook, Google) with the goal of building it out to meet the entire specification over time.
INSTALLATION
$ cpan
cpan> install Net::OAuth2
WEB SERVER EXAMPLE (Dancer)
# This example is simplified for illustrative purposes, see the complete code in /demo
use Dancer;
use Net::OAuth2::Client;
sub client {
Net::OAuth2::Client->new(
config->{client_id},
config->{client_secret},
site => 'https://graph.facebook.com',
)->web_server(
redirect_uri => uri_for('/auth/facebook/callback')
);
}
# Send user to authorize with service provider
get '/auth/facebook' => sub {
redirect client->authorize_url;
};
# User has returned with '?code=foo' appended to the URL.
get '/auth/facebook/callback' => sub {
# Use the auth code to fetch the access token
my $access_token = client->get_access_token(params->{code});
# Use the access token to fetch a protected resource
my $response = $access_token->get('/me');
# Do something with said resource...
if ($response->is_success) {
return "Yay, it worked: " . $response->decoded_content;
}
else {
return "Error: " . $response->status_line;
}
};
dance;
LICENSE AND COPYRIGHT
Copyright (C) 2010 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.
See http://dev.perl.org/licenses/ for more information.
About
OAuth 2.0 for Perl
Resources
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published
Languages
- Perl 100.0%