File Coverage

blib/lib/OIDC/Lite/Server/Endpoint/Token.pm
Criterion Covered Total %
statement 9 9 100.0
branch n/a
condition n/a
subroutine 3 3 100.0
pod n/a
total 12 12 100.0


line stmt bran cond sub pod time code
1             package OIDC::Lite::Server::Endpoint::Token;
2 1     1   1066 use strict;
  1         2  
  1         30  
3 1     1   4 use warnings;
  1         1  
  1         21  
4 1     1   4 use parent 'OAuth::Lite2::Server::Endpoint::Token';
  1         1  
  1         5  
5             use overload
6             q(&{}) => sub { shift->psgi_app },
7             fallback => 1;
8              
9             use OIDC::Lite::Server::GrantHandlers;
10             use OAuth::Lite2::Server::Error;
11              
12             sub support_grant_type {
13             my ($self, $type) = @_;
14             my $handler = OIDC::Lite::Server::GrantHandlers->get_handler($type)
15             or OAuth::Lite2::Server::Error::UnsupportedGrantType->throw;
16             $self->{grant_handlers}{$type} = $handler;
17             }
18              
19             =head1 NAME
20              
21             OIDC::Lite::Server::Endpoint::Token - token endpoint PSGI application
22              
23             =head1 SYNOPSIS
24              
25             token_endpoint.psgi
26              
27             use strict;
28             use warnings;
29             use Plack::Builder;
30             use OIDC::Lite::Server::Endpoint::Token;
31             use MyDataHandlerClass;
32              
33             builder {
34             my $app = OIDC::Lite::Server::Endpoint::Token->new(
35             data_handler => 'MyDataHandlerClass',
36             );
37             $app->support_grant_types(qw(authorization_code refresh_token));
38             $app;
39             };
40              
41             =head1 DESCRIPTION
42              
43             The object of this class behaves as PSGI application (subroutine reference).
44             This is for OpenID Connect token-endpoint.
45              
46             At first you have to make your custom class inheriting L,
47             and setup PSGI file with it.
48              
49             =head1 METHODS
50              
51             =head2 new( %params )
52              
53             =over 4
54              
55             =item data_handler
56              
57             name of your custom class that inherits L
58             and implements interface.
59              
60             =item error_uri
61              
62             Optional. URI that represents error description page.
63             This would be included in error responses.
64              
65             =back
66              
67             =head2 support_grant_type( $type )
68              
69             You can set 'authorization_code', 'password', 'client_credentials' or 'refresh_token'
70              
71             =head2 support_grant_types( @types )
72              
73             You can set 'authorization_code', 'password', 'client_credentials' or 'refresh_token'
74              
75             =head1 TEST
76              
77             You can test with L and some of client classes.
78              
79             my $app = OIDC::Lite::Server::Endpoint::Token->new(
80             data_handler => 'MyDataHandlerClass',
81             );
82             $app->support_grant_types(qw(authorization_code refresh_token));
83             my $mock_agent = OAuth::Lite2::Agent::PSGIMock->new(app => $app);
84             my $client = OAuth::Lite2::Client::UsernameAndPassword->new(
85             id => q{my_client_id},
86             secret => q{my_client_secret},
87             agent => $mock_agent,
88             );
89             my $token = $client->get_access_token(
90             username => q{foo},
91             password => q{bar},
92             );
93             ok($token);
94             is($token->access_token, q{access_token_value});
95              
96             =head1 AUTHOR
97              
98             Ryo Ito, Eritou.06@gmail.comE
99              
100             =head1 COPYRIGHT AND LICENSE
101              
102             Copyright (C) 2012 by Ryo Ito
103              
104             This library is free software; you can redistribute it and/or modify
105             it under the same terms as Perl itself, either Perl version 5.8.8 or,
106             at your option, any later version of Perl 5 you may have available.
107              
108             =cut
109              
110             1;