Gungho
view release on metacpan or search on metacpan
docs/ja/Gungho/Component/Authentication/Basic.pod view on Meta::CPAN
=head1 NAME
Gungho::Component::Authentication::Basic.ja - Gunghoã§Basicèªè¨¼ãè¡ã
=head1 SYNOPSIS
---
components:
- Authentication::Basic
credentials:
basic:
-
- http://example.com
- "Admin Only"
- username
- password
-
- http://example2.com
- "Admin Only"
- username2
docs/ja/Gungho/Component/Authentication/Basic.pod view on Meta::CPAN
=head2 setup($c)
ã³ã³ãã¼ãã³ããåæåãã¾ãã
=head2 authenticate($is_proxy, $realm, $request, $response)
Basicèªè¨¼ãè¡ãã¾ããèªè¨¼ãå¿
è¦ãªæåã®ãªã¯ã¨ã¹ãã401ã§å¤±æããå ´åã¯
èªè¨¼ãããã¼ãä»ä¸ãå度ãªã¯ã¨ã¹ããè¡ãã¾ãã
=head2 set_basic_credentials($uri, $realm, $uid, $pass)
æå®ã®URLã¨Realmã«å¯¾ãã¦èªè¨¼æ
å ±ãè¨å®ãã¾ãã
=head2 get_basic_credentials($uri, $realm)
æå®ã®URLã¨Realmã«å¯¾ãã¦èªè¨¼æ
å ±ãè¿ãã¾ã
=cut
lib/Gungho/Component/Authentication/Basic.pm view on Meta::CPAN
use MIME::Base64 ();
use URI;
__PACKAGE__->mk_classdata($_) for qw(basic_authentication);
sub setup
{
my $self = shift;
$self->basic_authentication({});
my $list = $self->config->{credentials}{basic};
if ($list) {
foreach my $conf (@$list) {
$self->set_basic_credentials(@$conf);
}
}
$self->next::method(@_);
}
sub authenticate
{
my ($self, $proxy, $auth_param, $req, $res) = @_;
my ($user, $pass) = $self->get_basic_credentials($req->url, $auth_param->{realm});
return 0 unless defined $user and defined $pass;
my $auth_header = $proxy ? "Proxy-Authorization" : "Authorization";
my $auth_value = "Basic " . MIME::Base64::encode("$user:$pass", "");
# Check if this is a repeated fialure to auth
my $r = $res;
while ($r) {
my $auth = $r->request->header($auth_header);
lib/Gungho/Component/Authentication/Basic.pm view on Meta::CPAN
$r = $r->previous;
}
my $referral = $req->clone;
$referral->header($auth_header => $auth_value);
$self->send_request($referral);
return 1;
}
sub set_basic_credentials
{
my $self = shift;
my ($uri, $realm, $uid, $pass) = @_;
if (! eval { $uri->isa('URI') }) {
$uri = URI->new($uri);
}
$self->basic_authentication()->{lc ($uri->host_port)}{$realm} = [$uid, $pass];
}
sub get_basic_credentials
{
my $self = shift;
my ($uri, $realm) = @_;
if (! eval { $uri->isa('URI') }) {
$uri = URI->new($uri);
}
if (exists $self->basic_authentication()->{lc($uri->host_port)}{$realm}) {
return @{$self->basic_authentication()->{lc($uri->host_port)}{$realm}};
lib/Gungho/Component/Authentication/Basic.pm view on Meta::CPAN
=head1 NAME
Gungho::Component::Authentication::Basic - Add Basic Auth To Gungho
=head1 SYNOPSIS
---
components:
- Authentication::Basic
credentials:
basic:
-
- http://example.com
- "Admin Only"
- username
- password
-
- http://example2.com
- "Admin Only"
- username2
lib/Gungho/Component/Authentication/Basic.pm view on Meta::CPAN
=head1 METHODS
=head2 setup($c)
Sets up the component
=head2 authenticate($is_proxy, $realm, $request, $response)
Does the WWW Authentication and redispatches the request
=head2 set_basic_credentials($uri, $realm, $uid, $pass)
Sets the credentials for a uri + realm.
=head2 get_basic_credentials($uri, $realm)
Get the credentials for a uri + realm.
=head1 CAVEATS
This component merely stores data in Gungho that can be used for authentication.
The Engine type that Gungho is currently using must respect the information.
=cut
t/03_live/twitter.t view on Meta::CPAN
if (! $username || ! $password) {
plan(skip_all => "Enable GUNGHO_TWITTER_USERNAME and GUNGHO_TWITTER_PASSWORD to run these tests");
} else {
plan(tests => 5);
use_ok("Gungho::Inline");
}
}
Gungho::Inline->run(
{
credentials => {
basic =>
[ [ 'http://twitter.com', 'Twitter API', $username, $password ] ]
},
components => ['Authentication::Basic'],
},
{
provider => \&provider,
handler => \&handler,
}
);
( run in 0.423 second using v1.01-cache-2.11-cpan-fd5d4e115d8 )