File Coverage

blib/lib/OAuth/Lite2/Server/DataHandler.pm
Criterion Covered Total %
statement 18 44 40.9
branch n/a
condition n/a
subroutine 6 18 33.3
pod 12 14 85.7
total 36 76 47.3


line stmt bran cond sub pod time code
1             package OAuth::Lite2::Server::DataHandler;
2              
3 9     9   404142 use strict;
  9         19  
  9         237  
4 9     9   40 use warnings;
  9         12  
  9         232  
5              
6 9     9   4015 use Params::Validate;
  9         61932  
  9         560  
7 9     9   4650 use OAuth::Lite2::Server::Error;
  9         23  
  9         4912  
8              
9             sub new {
10 53     53 0 571 my ($class, %args) = @_;
11 53         193 my $self = bless { request => undef, %args }, $class;
12 53         157 $self->init;
13 53         184 $self;
14             }
15              
16             sub request {
17 18     18 1 19 my $self = shift;
18 18         42 return $self->{request};
19             }
20              
21             sub init {
22 0     0 1   my $self = shift;
23             # template method
24             }
25              
26             sub validate_client {
27 0     0 1   my ($self, $client_id, $client_secret, $grant_type) = @_;
28 0           die "abstract method";
29 0           return 1;
30             }
31              
32             sub get_user_id {
33 0     0 1   my ($self, $username, $password) = @_;
34 0           die "abstract method";
35             }
36              
37             sub create_or_update_auth_info {
38 0     0 1   my ($self, %args) = @_;
39 0           Params::Validate::validate(@_, {
40             client_id => 1,
41             user_id => 1,
42             scope => { optional => 1 },
43             });
44 0           die "abstract method";
45             }
46              
47             sub create_or_update_access_token {
48 0     0 1   my ($self, %args) = @_;
49 0           Params::Validate::validate(@_, {
50             auth_info => 1,
51             # secret_type => 1,
52             });
53 0           die "abstract method";
54             }
55              
56             sub get_auth_info_by_code {
57 0     0 1   my ($self, $code) = @_;
58 0           die "abstract method";
59             }
60              
61             sub get_auth_info_by_refresh_token {
62 0     0 1   my ($self, $refresh_token) = @_;
63 0           die "abstract method";
64             }
65              
66             sub get_client_user_id {
67 0     0 0   my ($self, $client_id) = @_;
68 0           die "abstract method";
69             }
70              
71             sub validate_client_by_id {
72 0     0 1   my ($self, $client_id) = @_;
73 0           1;
74             }
75              
76             sub validate_user_by_id {
77 0     0 1   my ($self, $user_id) = @_;
78 0           1;
79             }
80              
81             sub get_access_token {
82 0     0 1   my ($self, $token) = @_;
83 0           die "abstract method";
84             }
85              
86             sub get_auth_info_by_id {
87 0     0 1   my ($self, $id) = @_;
88 0           die "abstract method";
89             }
90              
91             =head1 NAME
92              
93             OAuth::Lite2::Server::DataHandler - Base class that specifies interface for data handler for your service.
94              
95             =head1 SYNOPSIS
96              
97             =head1 DESCRIPTION
98              
99             This specifies interface to handle data stored on your application.
100             You have to inherit this, and implements subroutines according to the interface contract.
101             This is proxy or adapter that connects OAuth::Lite2 library to your service.
102              
103             =head1 METHODS
104              
105             =head2 init
106              
107             If your subclass need some initiation, implement in this method.
108              
109             =head1 INTERFACES
110              
111             =head2 request
112              
113             Returns object.
114              
115             =head2 validate_client( $client_id, $client_secret, $grant_type )
116              
117             This interface is used on Token Endpoint.
118             In spite of grant_type, all the time this method is called.
119              
120             You can check here the client_id is valid? and client credentials is not invalid?
121             And the client is allowed to use this grant_type?
122              
123             If it's OK, return 1. Return 0 if not.
124              
125             =head2 get_user_id( $username, $password )
126              
127             This interface is used on Token Endpoint, when requested grant_type is 'password'.
128             Username and password is passed. You check if the credentials is valid or not.
129             And if it's OK, return the user's identifier that is managed on your service.
130              
131             =head2 create_or_update_auth_info( %params )
132              
133             Create and save new authorization info.
134             Should return L object.
135              
136             =head2 create_or_update_access_token( %params )
137              
138             Create and save new access token.
139             Should return L object.
140              
141             =head2 get_auth_info_by_code( $code )
142              
143             This interface is used when client obtains access_token using authorization-code
144             that would be issued by server with user's authorization.
145             For instance, Web Server Profile requires this interface.
146              
147             Should return L object.
148              
149             =head2 get_auth_info_by_refresh_token( $refresh_token )
150              
151             This interface is used when refresh access_token.
152              
153             Should return L object.
154              
155             =head2 get_access_token( $token )
156              
157             This interface is used on protected resource endpoint.
158             See L.
159             get attributes that belongs to the token that is included
160             HTTP request accesses to the endpoint.
161             Should return L object.
162              
163             =head2 get_auth_info_by_id( $auth_id )
164              
165             This interface is used on protected resource endpoint.
166             See L.
167             This method is called after get_access_token method.
168             get authorization-info that is related to the $auth_id
169             that has relation with the access token.
170              
171             Should return L object.
172              
173             =head2 validate_client_by_id( $client_id )
174              
175             This fook is called on protected resource endpoint.
176             See L.
177              
178             After checking if token is valid, furthermore you can check
179             if the client related the token is valid in this method.
180              
181             If passed client_id is invalid for some reason, return 0.
182             If OK, return 1.
183              
184             =head2 validate_user_by_id( $user_id )
185              
186             This hook is called on protected resource endpoint.
187             See L.
188              
189             After checking if token is valid, furthermore you can check
190             if the user related the token is valid in this method.
191              
192             If passed user_id is invalid for some reason, return 0.
193             If OK, return 1.
194              
195             =head1 AUTHOR
196              
197             Lyo Kato, Elyo.kato@gmail.comE
198              
199             =head1 COPYRIGHT AND LICENSE
200              
201             Copyright (C) 2010 by Lyo Kato
202              
203             This library is free software; you can redistribute it and/or modify
204             it under the same terms as Perl itself, either Perl version 5.8.8 or,
205             at your option, any later version of Perl 5 you may have available.
206              
207             =cut
208              
209             1;