| 1 | package OIDC::Lite::Server::Endpoint::Token; | ||||||||||
| 2 | 2 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 2 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 2 | ▶ | use parent 'OAuth::Lite2::Server::Endpoint::Token'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | use overload | ||||||||||
| 6 | 16 | ▶ | q(&{}) => sub { shift->psgi_app }, | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 2 | ▶ | fallback => 1; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | |||||||||||
| 9 | 2 | ▶ | use OIDC::Lite::Server::GrantHandlers; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 2 | ▶ | use OAuth::Lite2::Server::Error; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | |||||||||||
| 12 | sub support_grant_type { | ||||||||||
| 13 | 5 | ▶ | my ($self, $type) = @_; | ||||||||
|
Subroutine
support_grant_type: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 14 | 5 | ▶ | my $handler = OIDC::Lite::Server::GrantHandlers->get_handler($type) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 15 | or OAuth::Lite2::Server::Error::UnsupportedGrantType->throw; | ||||||||||
| 16 | 4 | $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<OIDC::Lite::Server::DataHandler>, | ||||||||||
| 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<OIDC::Lite::Server::DataHandler> | ||||||||||
| 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<OAuth::Lite2::Agent::PSGIMock> 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, E<lt>ritou.06@gmail.comE<gt> | ||||||||||
| 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 | 2 | 1; | |||||||||