Apache-AuthTypeKey
view release on metacpan or search on metacpan
eg/login.pl view on Meta::CPAN
#!/usr/bin/perl -w
use strict;
use Apache::Util qw( escape_uri );
my $Protected = 'http://example.com/login-protected';
my $r = Apache->request;
$r->status(200);
my $prev = $r->prev;
my $uri = 'http://' . $prev->hostname . $prev->uri;
## If there are args, append them to the URI.
my $args = $prev->args;
if ($args) {
$uri .= "?$args";
}
my $token = $prev->dir_config('TypeKeyToken');
my $tk_url = $prev->dir_config('TypeKeyURL') ||
'https://www.typekey.com/t/typekey/login';
$uri = escape_uri("$Protected?destination=" . escape_uri($uri));
my $html = <<HTML;
<html>
<head>
<title>Login</title>
</head>
<body>
<a href="$tk_url?t=$token&v=1.1&_return=$uri">Log in via TypeKey</a>
</body>
</html>
lib/Apache/AuthTypeKey.pm view on Meta::CPAN
## expiration check on the signature.
$tk->skip_expiry_check(1);
my $res = $tk->verify(Apache::AuthTypeKey::Query->new($key));
$res ? $res->{name} : undef;
}
## This is needed for 2 reasons:
## 1. Authen::TypeKey currently expects a Query-type object.
## 2. Apache->args breaks on '=' signs in the key/value pairs.
package Apache::AuthTypeKey::Query;
use URI::Escape qw( uri_escape uri_unescape );
sub new {
my $class = shift;
my($key) = @_;
my %p;
for my $p (split /&/, $key) {
my($k, $v) = split /=/, $p, 2;
$p{uri_unescape($k)} = uri_unescape($v);
}
bless \%p, $class;
}
sub param { $_[0]{$_[1]} }
sub delete { delete $_[0]{$_[1]} }
sub as_string {
my $q = shift;
my @s;
while (my($k, $v) = each %$q) {
push @s, uri_escape($k) . '=' . uri_escape($v);
}
join '&', @s;
}
1;
__END__
=head1 NAME
Apache::AuthTypeKey - Apache authorization handler using TypeKey
( run in 2.483 seconds using v1.01-cache-2.11-cpan-df04353d9ac )