| 1 | package Catalyst::Authentication::Credential::YubiKey; | ||||||||||||||||||||||||||||
| 2 | 3 | ▶ | use Catalyst::Exception; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use Auth::Yubikey_WebClient; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 3 | ▶ | use Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 3 | ▶ | use MooseX::Types::Common::String qw/ NonEmptySimpleStr /; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 3 | ▶ | use namespace::autoclean; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | =head1 NAME | ||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | Catalyst::Authentication::Credential::YubiKey - YubiKey authentication | ||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | =head1 VERSION | ||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | Version 0.07 | ||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | Authenticate Catalyst apps with Yubico's YubiKey system. | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | Uses the Catalyst::Plugin::Authentication system. | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | use Catalyst qw( | ||||||||||||||||||||||||||||
| 23 | ... | ||||||||||||||||||||||||||||
| 24 | Authentication | ||||||||||||||||||||||||||||
| 25 | ... | ||||||||||||||||||||||||||||
| 26 | ); | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | __PACKAGE__->config( | ||||||||||||||||||||||||||||
| 29 | 'Plugin::Authentication' => { | ||||||||||||||||||||||||||||
| 30 | default => { | ||||||||||||||||||||||||||||
| 31 | credential => { | ||||||||||||||||||||||||||||
| 32 | class => 'YubiKey', | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | # This is your API ID, from http://api.yubico.com/get-api-key/ | ||||||||||||||||||||||||||||
| 35 | api_id => 666, | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | # This is your API Key, as above: | ||||||||||||||||||||||||||||
| 38 | api_key => 'aaaaaaad34db33fzzzzzzzzzz/abc=', | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | # This is the column in your store that contains the yubikey ID, | ||||||||||||||||||||||||||||
| 41 | # for mapping that ID to username or whatever. | ||||||||||||||||||||||||||||
| 42 | # It defaults to 'id' if not specified. | ||||||||||||||||||||||||||||
| 43 | id_for_store => 'id', | ||||||||||||||||||||||||||||
| 44 | }, | ||||||||||||||||||||||||||||
| 45 | ... | ||||||||||||||||||||||||||||
| 46 | }, | ||||||||||||||||||||||||||||
| 47 | }, | ||||||||||||||||||||||||||||
| 48 | ); | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | =head1 TODO | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | I am currently using Auth::Yubikey_WebClient as the underlying library for | ||||||||||||||||||||||||||||
| 53 | querying Yubico's webservice. However it would be nice if that library was | ||||||||||||||||||||||||||||
| 54 | improved to return more of the details, rather than just 'OK'. | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | Also would be good to support in-house authentication servers. (Since Yubico | ||||||||||||||||||||||||||||
| 57 | have open-sourced theirs, and some people may be using such.) | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | =head1 METHODS | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | =cut | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 3 | our $VERSION = '0.07'; | |||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 3 | has [qw/ api_key api_id /] => ( | |||||||||||||||||||||||||||
| 66 | isa => NonEmptySimpleStr, | ||||||||||||||||||||||||||||
| 67 | is => 'ro', | ||||||||||||||||||||||||||||
| 68 | required => 1 | ||||||||||||||||||||||||||||
| 69 | ); | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 3 | has id_for_store => ( | |||||||||||||||||||||||||||
| 72 | isa => NonEmptySimpleStr, | ||||||||||||||||||||||||||||
| 73 | is => 'ro', | ||||||||||||||||||||||||||||
| 74 | default => 'id' | ||||||||||||||||||||||||||||
| 75 | ); | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | =head2 BUILDARGS | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | Extracts the config | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | =cut | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | 3 | ▶ | sub BUILDARGS { | ||||||||||||||||||||||||||
|
Subroutine
BUILDARGS: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 84 | 3 | my ($class, $config, $app, $realm) = @_; | |||||||||||||||||||||||||||
| 85 | 3 | ▶ | unless ($config->{api_id} and $config->{api_key}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$config->{"api_id"} and $config->{"api_key"}
MC/DC50%1/2
$config->{"api_id"} and $config->{"api_key"}
$config->{"api_id"}
$config->{"api_key"}
Truth table66%2/3
A and B
A= $config->{"api_id"}B= $config->{"api_key"}
| |||||||||||||||||||||||||||||
| 86 | 1 | Catalyst::Exception->throw( | |||||||||||||||||||||||||||
| 87 | __PACKAGE__ . " credential for realm " . $realm->name . " missing api_id and api_key" | ||||||||||||||||||||||||||||
| 88 | ); | ||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||
| 90 | 2 | return $config; | |||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | =head2 authenticate | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | Standard authentication method, as per Cat-Auth-Credential standard. | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | =cut | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | 0 | ▶ | sub authenticate { | ||||||||||||||||||||||||||
|
Subroutine
authenticate: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 100 | 0 | my ($self, $c, $realm, $authinfo) = @_; | |||||||||||||||||||||||||||
| 101 | 0 | my $otp = $authinfo->{otp}; | |||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | 0 | my $result = Auth::Yubikey_WebClient::yubikey_webclient( | |||||||||||||||||||||||||||
| 104 | $otp, $self->api_id, $self->api_key | ||||||||||||||||||||||||||||
| 105 | ); | ||||||||||||||||||||||||||||
| 106 | 0 | ▶ | unless ($result eq 'OK') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 107 | 0 | $c->log->error("User auth failed: $result"); | |||||||||||||||||||||||||||
| 108 | 0 | return; | |||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | # The user ID is the first 2-12 characters.. but the next part is always | ||||||||||||||||||||||||||||
| 112 | # 32 characters. | ||||||||||||||||||||||||||||
| 113 | 0 | my $yubi_id = substr($otp, 0, -32); | |||||||||||||||||||||||||||
| 114 | 0 | my $user = $realm->find_user({ $self->id_for_store => $yubi_id }, $c); | |||||||||||||||||||||||||||
| 115 | 0 | ▶ | unless ($user) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 116 | 0 | $c->log->error("Authenticated user, but could not locate in " | |||||||||||||||||||||||||||
| 117 | ." our Store!"); | ||||||||||||||||||||||||||||
| 118 | 0 | return; | |||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||
| 120 | 0 | return $user; | |||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | Toby Corkindale, C<< <tjc at cpan.org> >> | ||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | =head1 BUGS | ||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | Please report any bugs or feature requests to | ||||||||||||||||||||||||||||
| 130 | C<bug-catalyst-authentication-credential-yubikey at rt.cpan.org>, or through | ||||||||||||||||||||||||||||
| 131 | the web interface at | ||||||||||||||||||||||||||||
| 132 | L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Catalyst-Authentication-Credential-YubiKey>. | ||||||||||||||||||||||||||||
| 133 | I will be notified, and then you'll automatically be notified of progress on | ||||||||||||||||||||||||||||
| 134 | your bug as I make changes. | ||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | =head1 SUPPORT | ||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | You can find documentation for this module with the perldoc command. | ||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | perldoc Catalyst::Authentication::Credential::YubiKey | ||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | You can also look for information at: | ||||||||||||||||||||||||||||
| 143 | http://github.com/TJC/Catalyst-Authentication-Credential-YubiKey | ||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||
| 145 | =over 4 | ||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | =item * RT: CPAN's request tracker | ||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Catalyst-Authentication-Credential-YubiKey> | ||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | =item * AnnoCPAN: Annotated CPAN documentation | ||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | L<http://annocpan.org/dist/Catalyst-Authentication-Credential-YubiKey> | ||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | =item * CPAN Ratings | ||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | L<http://cpanratings.perl.org/d/Catalyst-Authentication-Credential-YubiKey> | ||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||
| 159 | =item * Search CPAN | ||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | L<http://search.cpan.org/dist/Catalyst-Authentication-Credential-YubiKey/> | ||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||
| 163 | =back | ||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||
| 165 | =head1 COPYRIGHT & LICENSE | ||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||
| 167 | Copyright 2010-2012 Toby Corkindale, all rights reserved. | ||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||
| 169 | This program is free software; you can redistribute it and/or modify it | ||||||||||||||||||||||||||||
| 170 | under the same terms as Perl itself. | ||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||
| 172 | =cut | ||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||
| 174 | 3 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||
| 175 | 3 | 1; | |||||||||||||||||||||||||||