Authen-SCRAM
view release on metacpan or search on metacpan
lib/Authen/SCRAM/Server.pm view on Meta::CPAN
my $name = $self->_get_session("n");
if ( !$self->_const_eq_fcn->( $computed_key, $self->_get_session("_stored_key") ) ) {
croak "SCRAM authentication for user '$name' failed";
}
if ( my $authz = $self->_get_session("a") ) {
$self->auth_proxy_cb->( $name, $authz )
or croak("SCRAM authentication failed; '$name' not authorized to act as '$authz'");
}
$self->_set_session( _proof_ok => 1 );
my $server_sig =
$self->_hmac_fcn->( $self->_get_session('_server_key'), $self->_auth_msg );
$self->_set_session( v => $self->_base64($server_sig) );
$self->_join_reply('v');
}
#pod =method authorization_id
#pod
#pod $username = $client->authorization_id();
#pod
#pod This takes no arguments and returns the authorization identity resulting from
#pod the SCRAM exchange. This is the client-supplied authorization identity (if one
#pod was provided and validated) or else the successfully authenticated identity.
#pod
#pod =cut
sub authorization_id {
my ($self) = @_;
return '' unless $self->_get_session("_proof_ok");
my $authz = $self->_get_session("a");
return ( defined($authz) && length($authz) ) ? $authz : $self->_get_session("n");
}
1;
# vim: ts=4 sts=4 sw=4 et:
__END__
=pod
=encoding UTF-8
=head1 NAME
Authen::SCRAM::Server - RFC 5802 SCRAM Server
=head1 VERSION
version 0.011
=head1 SYNOPSIS
use Authen::SCRAM::Server;
use Try::Tiny;
$server = Authen::SCRAM::Server->new(
credential_cb => \&get_credentials,
);
$username = try {
# get client-first-message
$server_first = $server->first_msg( $client_first );
# send to client and get client-final-message
$server_final = $server->final_msg( $client_final );
# send to client
return $server->authorization_id; # returns valid username
}
catch {
die "Authentication failed!"
};
=head1 DESCRIPTION
This module implements the server-side SCRAM algorithm.
=head1 NAME
Authen::SCRAM::Server - RFC 5802 SCRAM Server
=head1 VERSION
version 0.011
=head1 ATTRIBUTES
=head2 credential_cb (required)
This attribute must contain a code reference that takes a username (as a
character string normalized by SASLprep) and returns the four user-credential
parameters required by SCRAM: C<salt>, C<StoredKey>, C<ServerKey>, and
C<iteration count>. The C<salt>, C<StoredKey> and C<ServerKey> must be
provided as octets (i.e. B<NOT> base64 encoded).
If the username is unknown, it should return an empty list.
($salt, $stored_key, $server_key, $iterations) =
$server->credential_cb->( $username );
See L<RFC 5802: SCRAM Algorithm Overview|http://tools.ietf.org/html/rfc5802#section-3>
for details.
=head2 auth_proxy_cb
If provided, this attribute must contain a code reference that takes an
B<authentication> username and a B<authorization> username (both as character
strings), and return a true value if the authentication username is permitted
to act as the authorization username:
$bool = $server->auth_proxy_cb->(
( run in 0.743 second using v1.01-cache-2.11-cpan-39bf76dae61 )