1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
|
package OAuth::Lite2::ParamMethods;
use strict;
use warnings;
use OAuth::Lite2::ParamMethod::AuthHeader;
use OAuth::Lite2::ParamMethod::FormEncodedBody;
use OAuth::Lite2::ParamMethod::URIQueryParameter;
use base 'Exporter';
our %EXPORT_TAGS = ( all => [qw/
AUTH_HEADER FORM_BODY URI_QUERY
/] );
our @EXPORT_OK = map { @$_ } values %EXPORT_TAGS;
use constant AUTH_HEADER => 0;
use constant FORM_BODY => 1;
use constant URI_QUERY => 2;
my @METHODS = (
OAuth::Lite2::ParamMethod::AuthHeader->new,
OAuth::Lite2::ParamMethod::FormEncodedBody->new,
OAuth::Lite2::ParamMethod::URIQueryParameter->new,
);
sub get_param_parser {
my ($self, $req) = @_;
for my $method ( @METHODS ) {
return $method if $method->match($req)
}
return;
}
sub get_request_builder {
my ($self, $type) = @_;
return $METHODS[ $type ];
}
=head1 NAME
OAuth::Lite2::ParamMethods - store of builders/parsers for OAuth 2.0 parameters
=head1 SYNOPSIS
use OAuth::Lite2::ParamMethods qw(AUTH_HEADER FORM_BODY URI_QUERY);
# client side
my $builder = OAuth::Lite2::ParamMethods->get_request_builder( AUTH_HEADER );
my $req = $builder->build_request(...);
# server side
my $parser = OAuth::Lite2::ParamMethods->get_param_parser( $plack_request )
or $app->error("This is not OAuth 2.0 request");
my ($token, $params) = $parser->parse( $plack_request );
=head1 DESCRIPTION
Store of builders/parsers for OAuth 2.0 parameters
=head1 CONSTANTS
=over 4
=item AUTH_HEADER
=item FORM_BODY
=item URI_QUERY
=back
=head1 METHODS
=head2 get_param_parser( $plack_request )
Pass a L<Plack::Request> object and proper parser for the request.
my $parser = OAuth::Lite2::ParamMethods->get_param_parser( $plack_request )
or $app->error("This is not OAuth 2.0 request");
my ($token, $params) = $parser->parse( $plack_request );
=head2 get_request_builder( $type )
Returns proper HTTP request builder for the passed $type.
my $builder = OAuth::Lite2::ParamMethods->get_request_builder( AUTH_HEADER );
my $req = $builder->build_request(...);
=head1 SEE ALSO
L<OAuth::Lite2::ParamMethod::AuthHeader>
L<OAuth::Lite2::ParamMethod::FormEncodedBody>
L<OAuth::Lite2::ParamMethod::URIQueryParameter>
=head1 AUTHOR
Lyo Kato, E<lt>lyo.kato@gmail.comE<gt>
=head1 COPYRIGHT AND LICENSE
Copyright (C) 2010 by Lyo Kato
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself, either Perl version 5.8.8 or,
at your option, any later version of Perl 5 you may have available.
=cut
1;
|