File Coverage

blib/lib/OAuth/Lite2/Server/DataHandler.pm
Criterion Covered Total %
statement 18 51 35.2
branch n/a
condition n/a
subroutine 6 22 27.2
pod 16 18 88.8
total 40 91 43.9


line stmt bran cond sub pod time code
1             package OAuth::Lite2::Server::DataHandler;
2              
3 16     16   662212 use strict;
  16         21  
  16         339  
4 16     16   49 use warnings;
  16         20  
  16         283  
5              
6 16     16   5856 use Params::Validate;
  16         76529  
  16         763  
7 16     16   5250 use OAuth::Lite2::Server::Error;
  16         24  
  16         6496  
8              
9             sub new {
10 79     79 0 800 my ($class, %args) = @_;
11 79         228 my $self = bless { request => undef, %args }, $class;
12 79         193 $self->init;
13 79         241 $self;
14             }
15              
16             sub request {
17 40     40 1 50 my $self = shift;
18 40         91 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             }
30              
31             sub get_user_id {
32 0     0 1   my ($self, $username, $password) = @_;
33 0           die "abstract method";
34             }
35              
36             sub create_or_update_auth_info {
37 0     0 1   my ($self, %args) = @_;
38 0           Params::Validate::validate(@_, {
39             client_id => 1,
40             user_id => 1,
41             scope => { optional => 1 },
42             });
43 0           die "abstract method";
44             }
45              
46             sub create_or_update_access_token {
47 0     0 1   my ($self, %args) = @_;
48 0           Params::Validate::validate(@_, {
49             auth_info => 1,
50             # secret_type => 1,
51             });
52 0           die "abstract method";
53             }
54              
55             sub get_auth_info_by_code {
56 0     0 1   my ($self, $code) = @_;
57 0           die "abstract method";
58             }
59              
60             sub get_auth_info_by_refresh_token {
61 0     0 1   my ($self, $refresh_token) = @_;
62 0           die "abstract method";
63             }
64              
65             sub get_client_user_id {
66 0     0 0   my ($self, $client_id) = @_;
67 0           die "abstract method";
68             }
69              
70             sub validate_client_by_id {
71 0     0 1   my ($self, $client_id) = @_;
72 0           1;
73             }
74              
75             sub validate_user_by_id {
76 0     0 1   my ($self, $user_id) = @_;
77 0           1;
78             }
79              
80             sub get_access_token {
81 0     0 1   my ($self, $token) = @_;
82 0           die "abstract method";
83             }
84              
85             sub get_auth_info_by_id {
86 0     0 1   my ($self, $id) = @_;
87 0           die "abstract method";
88             }
89              
90             sub get_group_id_by_client_id {
91 0     0 1   my ($self, $client_id) = @_;
92 0           die "abstract method";
93             }
94              
95             sub validate_grouping_scope {
96 0     0 1   my ($self, $client_id, $scope) = @_;
97 0           die "abstract method";
98             }
99              
100             sub create_server_state {
101 0     0 1   my ($self, %args) = @_;
102 0           die "abstract method";
103             }
104              
105             sub get_user_id_by_external_assertion{
106 0     0 1   my ($self, %args) = @_;
107 0           die "abstract method";
108             }
109              
110             =head1 NAME
111              
112             OAuth::Lite2::Server::DataHandler - Base class that specifies interface for data handler for your service.
113              
114             =head1 DESCRIPTION
115              
116             This connects OAuth::Lite2 library to your service.
117              
118             This specifies an interface to handle data stored in your application. You must
119             inherit this and implement the subroutines according to the interface contract.
120              
121             =head1 SYNOPSIS
122              
123             package YourDataHandler;
124            
125             use strict;
126             use warnings;
127              
128             use parent 'OAuth::Lite2::Server::DataHandler';
129              
130             =head1 METHODS
131              
132             =head2 init
133              
134             This method can be implemented to initialize your subclass.
135              
136             =head1 INTERFACES
137              
138             =head2 request
139              
140             Returns object.
141              
142             =head2 validate_client( $client_id, $client_secret, $grant_type )
143              
144             This method is used by Token Endpoint. This method will be called all the time,
145             regardless of the grant_type setting.
146              
147             This is the place to check if the client_id and client credentials are valid,
148             as well as checking if the client is allowed to use this grant_type.
149              
150             If all the checks are successful, return 1. Otherwise return 0.
151              
152             =head2 get_user_id( $username, $password )
153              
154             This method is used by Token Endpoint, when requested grant_type is 'password'.
155              
156             The username and password are provided. You should check if the credentials are
157             valid or not.
158              
159             If the checks are successful, return the user's identifier. The user's
160             identifier is managed by your service.
161              
162             =head2 create_or_update_auth_info( %params )
163              
164             Create and save new authorization info.
165             Should return L object.
166              
167             =head2 create_or_update_access_token( %params )
168              
169             Create and save new access token.
170             Should return L object.
171              
172             =head2 get_auth_info_by_code( $code )
173              
174             This method is used when the client obtains an access_token using an
175             authorization-code that was issued by server with user's authorization.
176              
177             The Web Server Profile requires this interface.
178              
179             Should return L object.
180              
181             =head2 get_auth_info_by_refresh_token( $refresh_token )
182              
183             This method is used when the access_token is refreshed.
184              
185             Should return L object.
186              
187             =head2 get_access_token( $token )
188              
189             This interface is used on a protected resource endpoint.
190             See L.
191              
192             Returns an access token which allows access to the protected attributes.
193             Should return L object.
194              
195             =head2 get_auth_info_by_id( $auth_id )
196              
197             This method is used on a protected resource endpoint.
198             See L.
199              
200             This method is called after the get_access_token method. Returns
201             authorization-info that is related to the $auth_id and access-token.
202              
203             Should return L object.
204              
205             =head2 validate_client_by_id( $client_id )
206              
207             This hook is called on protected resource endpoint.
208             See L.
209              
210             After checking if the token is valid, you can check if the client related the
211             token is valid in this method.
212              
213             If the validation of the client_id is successful, return 1. Otherwise return 0.
214              
215             =head2 validate_user_by_id( $user_id )
216              
217             This hook is called on protected resource endpoint.
218             See L.
219              
220             After checking if token is valid, you can check if the user related the token
221             is valid in this method.
222              
223             If the validation of the user is successful, return 1. Otherwise return 0.
224              
225             =head2 get_group_id_by_client_id ( $client_id )
226              
227             If client_id has group_id, return it.
228              
229             =head2 validate_grouping_scope ( $client_id, $scope )
230              
231             If scope value is allowed, return 1.
232              
233             =head2 create_server_state ( $client_id )
234              
235             Create and save L object.
236              
237             =head2 get_user_id_by_external_assertion ( %params )
238              
239             This method is used by Token Endpoint, when requested grant_type is 'federation-bearer'.
240              
241             The external service assertion is provided. You should check if the related external service account is valid or not.
242             If the checks are successful, return the user's identifier. The user's identifier is managed by your service.
243              
244             =head1 AUTHOR
245              
246             Ryo Ito, Eritou.06@gmail.comE
247              
248             Lyo Kato, Elyo.kato@gmail.comE
249              
250             =head1 COPYRIGHT AND LICENSE
251              
252             Copyright (C) 2010 by Lyo Kato
253              
254             This library is free software; you can redistribute it and/or modify
255             it under the same terms as Perl itself, either Perl version 5.8.8 or,
256             at your option, any later version of Perl 5 you may have available.
257              
258             =cut
259              
260             1;