| 1 | package OAuth::Lite2::Server::DataHandler; | ||
| 2 | |||
| 3 | 16 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 16 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | |||
| 6 | 16 | ▶ | use Params::Validate; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 7 | 16 | ▶ | use OAuth::Lite2::Server::Error; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 8 | |||
| 9 | sub new { | ||
| 10 | 137 | ▶ | my ($class, %args) = @_; |
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 11 | 137 | my $self = bless { request => undef, %args }, $class; | |
| 12 | 137 | $self->init; | |
| 13 | 137 | $self; | |
| 14 | } | ||
| 15 | |||
| 16 | sub request { | ||
| 17 | 86 | ▶ | my $self = shift; |
|
Subroutine
request: called CC=1 SCAR=0.0
Pod
documented
| |||
| 18 | 86 | return $self->{request}; | |
| 19 | } | ||
| 20 | |||
| 21 | sub init { | ||
| 22 | 0 | ▶ | my $self = shift; |
|
Subroutine
init: not called CC=1 SCAR=6.9
Pod
documented
| |||
| 23 | # template method | ||
| 24 | } | ||
| 25 | |||
| 26 | sub validate_client { | ||
| 27 | 0 | ▶ | my ($self, $client_id, $client_secret, $grant_type) = @_; |
|
Subroutine
validate_client: not called CC=1 SCAR=6.9
Pod
documented
| |||
| 28 | 0 | die "abstract method"; | |
| 29 | } | ||
| 30 | |||
| 31 | sub get_user_id { | ||
| 32 | 0 | ▶ | my ($self, $username, $password) = @_; |
|
Subroutine
get_user_id: not called CC=1 SCAR=6.9
Pod
documented
| |||
| 33 | 0 | die "abstract method"; | |
| 34 | } | ||
| 35 | |||
| 36 | sub create_or_update_auth_info { | ||
| 37 | 0 | ▶ | my ($self, %args) = @_; |
|
Subroutine
create_or_update_auth_info: not called CC=1 SCAR=6.9
Pod
documented
| |||
| 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 | ▶ | my ($self, %args) = @_; |
|
Subroutine
create_or_update_access_token: not called CC=1 SCAR=6.9
Pod
documented
| |||
| 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 | ▶ | my ($self, $code) = @_; |
|
Subroutine
get_auth_info_by_code: not called CC=1 SCAR=6.9
Pod
documented
| |||
| 57 | 0 | die "abstract method"; | |
| 58 | } | ||
| 59 | |||
| 60 | sub get_auth_info_by_refresh_token { | ||
| 61 | 0 | ▶ | my ($self, $refresh_token) = @_; |
|
Subroutine
get_auth_info_by_refresh_token: not called CC=1 SCAR=6.9
Pod
documented
| |||
| 62 | 0 | die "abstract method"; | |
| 63 | } | ||
| 64 | |||
| 65 | sub get_client_user_id { | ||
| 66 | 0 | ▶ | my ($self, $client_id) = @_; |
|
Subroutine
get_client_user_id: not called CC=1 SCAR=6.9
Pod
undocumented
| |||
| 67 | 0 | die "abstract method"; | |
| 68 | } | ||
| 69 | |||
| 70 | sub validate_client_by_id { | ||
| 71 | 0 | ▶ | my ($self, $client_id) = @_; |
|
Subroutine
validate_client_by_id: not called CC=1 SCAR=6.9
Pod
documented
| |||
| 72 | 0 | 1; | |
| 73 | } | ||
| 74 | |||
| 75 | sub validate_user_by_id { | ||
| 76 | 0 | ▶ | my ($self, $user_id) = @_; |
|
Subroutine
validate_user_by_id: not called CC=1 SCAR=6.9
Pod
documented
| |||
| 77 | 0 | 1; | |
| 78 | } | ||
| 79 | |||
| 80 | sub get_access_token { | ||
| 81 | 0 | ▶ | my ($self, $token) = @_; |
|
Subroutine
get_access_token: not called CC=1 SCAR=6.9
Pod
documented
| |||
| 82 | 0 | die "abstract method"; | |
| 83 | } | ||
| 84 | |||
| 85 | sub get_auth_info_by_id { | ||
| 86 | 0 | ▶ | my ($self, $id) = @_; |
|
Subroutine
get_auth_info_by_id: not called CC=1 SCAR=6.9
Pod
documented
| |||
| 87 | 0 | die "abstract method"; | |
| 88 | } | ||
| 89 | |||
| 90 | sub get_group_id_by_client_id { | ||
| 91 | 0 | ▶ | my ($self, $client_id) = @_; |
|
Subroutine
get_group_id_by_client_id: not called CC=1 SCAR=6.9
Pod
documented
| |||
| 92 | 0 | die "abstract method"; | |
| 93 | } | ||
| 94 | |||
| 95 | sub validate_grouping_scope { | ||
| 96 | 0 | ▶ | my ($self, $client_id, $scope) = @_; |
|
Subroutine
validate_grouping_scope: not called CC=1 SCAR=6.9
Pod
documented
| |||
| 97 | 0 | die "abstract method"; | |
| 98 | } | ||
| 99 | |||
| 100 | sub create_server_state { | ||
| 101 | 0 | ▶ | my ($self, %args) = @_; |
|
Subroutine
create_server_state: not called CC=1 SCAR=6.9
Pod
documented
| |||
| 102 | 0 | die "abstract method"; | |
| 103 | } | ||
| 104 | |||
| 105 | sub get_user_id_by_external_assertion{ | ||
| 106 | 0 | ▶ | my ($self, %args) = @_; |
|
Subroutine
get_user_id_by_external_assertion: not called CC=1 SCAR=6.9
Pod
documented
| |||
| 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 <Plack::Request> 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<OAuth::Lite2::Model::AuthInfo> object. | ||
| 166 | |||
| 167 | =head2 create_or_update_access_token( %params ) | ||
| 168 | |||
| 169 | Create and save new access token. | ||
| 170 | Should return L<OAuth::Lite2::Model::AccessToken> 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<OAuth::Lite2::Model::AuthInfo> 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<OAuth::Lite2::Model::AuthInfo> object. | ||
| 186 | |||
| 187 | =head2 get_access_token( $token ) | ||
| 188 | |||
| 189 | This interface is used on a protected resource endpoint. | ||
| 190 | See L<Plack::Middleware::Auth::OAuth2::ProtectedResource>. | ||
| 191 | |||
| 192 | Returns an access token which allows access to the protected attributes. | ||
| 193 | Should return L<OAuth::Lite2::Model::AccessToken> 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<Plack::Middleware::Auth::OAuth2::ProtectedResource>. | ||
| 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<OAuth::Lite2::Model::AuthInfo> object. | ||
| 204 | |||
| 205 | =head2 validate_client_by_id( $client_id ) | ||
| 206 | |||
| 207 | This hook is called on protected resource endpoint. | ||
| 208 | See L<Plack::Middleware::Auth::OAuth2::ProtectedResource>. | ||
| 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<Plack::Middleware::Auth::OAuth2::ProtectedResource>. | ||
| 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<OAuth::Lite2::Model::ServerState> 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, E<lt>ritou.06@gmail.comE<gt> | ||
| 247 | |||
| 248 | Lyo Kato, E<lt>lyo.kato@gmail.comE<gt> | ||
| 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 | 16 | 1; | |