1Net::OAuth::Client(3) User Contributed Perl DocumentationNet::OAuth::Client(3)
2
3
4

NAME

6       Net::OAuth::Client - OAuth 1.0A Client
7

SYNOPSIS

9         # Web Server Example (Dancer)
10
11         # This example is simplified for illustrative purposes, see the complete code in /demo
12
13         # Note that client_id is the Consumer Key and client_secret is the Consumer Secret
14
15         use Dancer;
16         use Net::OAuth::Client;
17
18         sub client {
19               Net::OAuth::Client->new(
20                       config->{client_id},
21                       config->{client_secret},
22                       site => 'https://www.google.com/',
23                       request_token_path => '/accounts/OAuthGetRequestToken?scope=https%3A%2F%2Fwww.google.com%2Fm8%2Ffeeds%2F',
24                       authorize_path => '/accounts/OAuthAuthorizeToken',
25                       access_token_path => '/accounts/OAuthGetAccessToken',
26                       callback => uri_for("/auth/google/callback"),
27                       session => \&session,
28               );
29         }
30
31         # Send user to authorize with service provider
32         get '/auth/google' => sub {
33               redirect client->authorize_url;
34         };
35
36         # User has returned with token and verifier appended to the URL.
37         get '/auth/google/callback' => sub {
38
39               # Use the auth code to fetch the access token
40               my $access_token =  client->get_access_token(params->{oauth_token}, params->{oauth_verifier});
41
42               # Use the access token to fetch a protected resource
43               my $response = $access_token->get('/m8/feeds/contacts/default/full');
44
45               # Do something with said resource...
46
47               if ($response->is_success) {
48                 return "Yay, it worked: " . $response->decoded_content;
49               }
50               else {
51                 return "Error: " . $response->status_line;
52               }
53         };
54
55         dance;
56

DESCRIPTION

58       Net::OAuth::Client represents an OAuth client or consumer.
59
60       WARNING: Net::OAuth::Client is alpha code.  The rest of Net::OAuth is
61       quite stable but this particular module is new, and is under-documented
62       and under-tested.
63

METHODS

65       new($client_id, $client_secret, %params)
66           Create a new Client
67
68           •   $client_id
69
70               AKA Consumer Key - you get this from the service provider when
71               you register your application.
72
73           •   $client_secret
74
75               AKA Consumer Secret - you get this from the service provider
76               when you register your application.
77
78           •   $params{site}
79
80           •   $params{request_token_path}
81
82           •   $params{authorize_path}
83
84           •   $params{access_token_path}
85
86           •   $params{callback}
87
88           •   $params{session}
89
91       Copyright 2011 Keith Grennan.
92
93       This program is free software; you can redistribute it and/or modify it
94       under the terms of either: the GNU General Public License as published
95       by the Free Software Foundation; or the Artistic License.
96
97       See http://dev.perl.org/licenses/ for more information.
98
99
100
101perl v5.34.0                      2022-01-21             Net::OAuth::Client(3)
Impressum