| 1 | package Catalyst::Authentication::Store::MongoDB; | ||||||||||||
| 2 | |||||||||||||
| 3 | 2 | ▶ | use 5.006; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | 2 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | 2 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 6 | |||||||||||||
| 7 | =head1 NAME | ||||||||||||
| 8 | |||||||||||||
| 9 | Catalyst::Authentication::Store::MongoDB - L<MongoDB> backend for | ||||||||||||
| 10 | Catalyst::Plugin::Authentication | ||||||||||||
| 11 | |||||||||||||
| 12 | =head1 VERSION | ||||||||||||
| 13 | |||||||||||||
| 14 | Version 0.02 | ||||||||||||
| 15 | |||||||||||||
| 16 | =cut | ||||||||||||
| 17 | |||||||||||||
| 18 | 2 | our $VERSION = '0.02'; | |||||||||||
| 19 | |||||||||||||
| 20 | =head1 SYNOPSIS | ||||||||||||
| 21 | |||||||||||||
| 22 | This module links a subclass of MongoDB to your Catalyst application as a user | ||||||||||||
| 23 | store for the Authentication plugin. | ||||||||||||
| 24 | |||||||||||||
| 25 | <Plugin::Authentication> | ||||||||||||
| 26 | <default> | ||||||||||||
| 27 | <credential> | ||||||||||||
| 28 | class Password | ||||||||||||
| 29 | password_type self_check | ||||||||||||
| 30 | </credential> | ||||||||||||
| 31 | <store> | ||||||||||||
| 32 | class MongoDB | ||||||||||||
| 33 | user_collection user | ||||||||||||
| 34 | user_class Catalyst::Authentication::User::Hash | ||||||||||||
| 35 | model MongoDB | ||||||||||||
| 36 | database db | ||||||||||||
| 37 | </store> | ||||||||||||
| 38 | </default> | ||||||||||||
| 39 | </Plugin::Authentication> | ||||||||||||
| 40 | |||||||||||||
| 41 | Then use it as normal | ||||||||||||
| 42 | |||||||||||||
| 43 | sub login : Local { | ||||||||||||
| 44 | my ($self, $c) = @_; | ||||||||||||
| 45 | $c->authenticate({ | ||||||||||||
| 46 | username => $username, | ||||||||||||
| 47 | password => $password | ||||||||||||
| 48 | }); | ||||||||||||
| 49 | } | ||||||||||||
| 50 | |||||||||||||
| 51 | =head1 CONFIGURATION | ||||||||||||
| 52 | |||||||||||||
| 53 | =head2 class | ||||||||||||
| 54 | |||||||||||||
| 55 | The configuration required by L<Catalyst::Plugin::Authentication> to load this | ||||||||||||
| 56 | store in the first place. | ||||||||||||
| 57 | |||||||||||||
| 58 | =head2 user_collection | ||||||||||||
| 59 | |||||||||||||
| 60 | The collection in your database that holds users. | ||||||||||||
| 61 | |||||||||||||
| 62 | =head2 user_class | ||||||||||||
| 63 | |||||||||||||
| 64 | Some subclass of Catalyst::Authentication::User to bless the returned objects | ||||||||||||
| 65 | as. | ||||||||||||
| 66 | |||||||||||||
| 67 | =head2 model | ||||||||||||
| 68 | |||||||||||||
| 69 | The model name that you'd give to $c->model. It is expected that your model | ||||||||||||
| 70 | is a L<MongoDB> subclass. | ||||||||||||
| 71 | |||||||||||||
| 72 | =head2 database | ||||||||||||
| 73 | |||||||||||||
| 74 | The database that your user_collection is a collection in. | ||||||||||||
| 75 | |||||||||||||
| 76 | =cut | ||||||||||||
| 77 | |||||||||||||
| 78 | 0 | ▶ | sub new { | ||||||||||
|
Subroutine
new: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||
| 79 | 0 | my ($class, $config, $app) = @_; | |||||||||||
| 80 | |||||||||||||
| 81 | 0 | ▶ | $config->{user_class} //= 'Catalyst::Authentication::User::Hash'; | ||||||||||
|
Condition0%0/2
$config->{"user_class"} //= "Catalyst::Authentication::User::Hash"
MC/DC0%0/1
$config->{"user_class"} //= "Catalyst::Authentication::User::Hash"
$config->{"user_class"}
Truth table0%0/2
A
A= $config->{"user_class"}
| |||||||||||||
| 82 | |||||||||||||
| 83 | 0 | my $self = { | |||||||||||
| 84 | config => $config | ||||||||||||
| 85 | }; | ||||||||||||
| 86 | |||||||||||||
| 87 | 0 | bless $self, $class; | |||||||||||
| 88 | } | ||||||||||||
| 89 | |||||||||||||
| 90 | 0 | ▶ | sub from_session { | ||||||||||
|
Subroutine
from_session: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||
| 91 | 0 | my ($self, $c, $frozen) = @_; | |||||||||||
| 92 | |||||||||||||
| 93 | my $user = $c->model($self->{config}->{model}) | ||||||||||||
| 94 | ->connection | ||||||||||||
| 95 | ->get_database($self->{config}->{database}) | ||||||||||||
| 96 | ->get_collection($self->{config}->{user_collection}) | ||||||||||||
| 97 | 0 | ->find_one({ | |||||||||||
| 98 | _id => MongoDB::OID->new(value => $frozen) | ||||||||||||
| 99 | }); | ||||||||||||
| 100 | |||||||||||||
| 101 | 0 | ▶ | bless $user, $self->{config}->{user_class} if $user; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 102 | 0 | return $user; | |||||||||||
| 103 | } | ||||||||||||
| 104 | |||||||||||||
| 105 | 0 | ▶ | sub for_session { | ||||||||||
|
Subroutine
for_session: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 106 | 0 | my ($self, $c, $user) = @_; | |||||||||||
| 107 | |||||||||||||
| 108 | 0 | return $user->{_id}->{value}; | |||||||||||
| 109 | } | ||||||||||||
| 110 | |||||||||||||
| 111 | 0 | ▶ | sub find_user { | ||||||||||
|
Subroutine
find_user: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||
| 112 | 0 | my ($self, $authinfo, $c) = @_; | |||||||||||
| 113 | |||||||||||||
| 114 | # note to self before I forget: password is deleted from $authinfo by the | ||||||||||||
| 115 | # realm when finding the user. kthx | ||||||||||||
| 116 | my $user = $c->model($self->{config}->{model}) | ||||||||||||
| 117 | ->connection | ||||||||||||
| 118 | ->get_database($self->{config}->{database}) | ||||||||||||
| 119 | ->get_collection($self->{config}->{user_collection}) | ||||||||||||
| 120 | 0 | ->find_one($authinfo); | |||||||||||
| 121 | |||||||||||||
| 122 | 0 | ▶ | return undef unless $user; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 123 | |||||||||||||
| 124 | 0 | bless $user, $self->{config}->{user_class}; | |||||||||||
| 125 | } | ||||||||||||
| 126 | |||||||||||||
| 127 | 0 | ▶ | sub user_supports { | ||||||||||
|
Subroutine
user_supports: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 128 | 0 | my $self = shift; | |||||||||||
| 129 | 0 | $self->{config}->{user_class}->supports( @_ ); | |||||||||||
| 130 | } | ||||||||||||
| 131 | |||||||||||||
| 132 | =head1 AUTHOR | ||||||||||||
| 133 | |||||||||||||
| 134 | Altreus, C<< <altreus at cpan.org> >> | ||||||||||||
| 135 | |||||||||||||
| 136 | =head1 BUGS | ||||||||||||
| 137 | |||||||||||||
| 138 | I'll be amazed if this works for you at all. | ||||||||||||
| 139 | |||||||||||||
| 140 | Bugs and requests to github please - | ||||||||||||
| 141 | https://github.com/Altreus/Catalyst-Authentication-Store-MongoDB/issues | ||||||||||||
| 142 | |||||||||||||
| 143 | =head1 SUPPORT | ||||||||||||
| 144 | |||||||||||||
| 145 | You are reading all the support you're likely to get. | ||||||||||||
| 146 | |||||||||||||
| 147 | =head1 ACKNOWLEDGEMENTS | ||||||||||||
| 148 | |||||||||||||
| 149 | Thanks to BOBTFISH for wracking his brains to try to remember how this stuff | ||||||||||||
| 150 | works. | ||||||||||||
| 151 | |||||||||||||
| 152 | =head1 LICENSE AND COPYRIGHT | ||||||||||||
| 153 | |||||||||||||
| 154 | Copyright 2012 Altreus. | ||||||||||||
| 155 | |||||||||||||
| 156 | MIT licence. Go nuts. | ||||||||||||
| 157 | |||||||||||||
| 158 | |||||||||||||
| 159 | =cut | ||||||||||||
| 160 | |||||||||||||
| 161 | 2 | 1; # End of Catalyst::Authentication::Store::MongoDB | |||||||||||