Web::Authenticate::Session::Storage::Handler::SQL - Implementation of Web::Authenticate::Session::Storage::Handler::Role that can be used with MySQL or SQLite.
version 0.013
This Web::Authenticate::Session::Storage::Handler::Role is meant to be used with a very specific table structure:
CREATE TABLE sessions ( id INTEGER PRIMARY KEY AUTO_INCREMENT, user_id INTEGER NOT NULL UNIQUE, session_id VARCHAR(255) NOT NULL UNIQUE, expires INTEGER NOT NULL );
Other columns can exists, and the names of the table and column can change. But at least these columns must exist in order for this storage handler to work properly. Also, the primary key does not have to be an integer, and could even be the session_id. Also, the user_id does not need to be unique if you want to allow multiple sessions for a user by setting "allow_multiple_sessions_per_user" in Web::Authenticate to true.
Sets the Web::Authenticate::User::Storage::Handler::Role to be used. This is required. Default is Web::Authenticate::User::Storage::Handler::SQL created with "dbix_raw".
Sets the name of the sessions table that will be used when querying the database. Default is 'sessions'.
Sets the name of the session id field that will be used when querying the database. Default is 'session_id'.
Sets the name of the user_id field that will be used when querying the database. Default is 'user_id'.
A session id will only be valid from the user agent it was originally created on. If invalid, the session will be deleted in storage. If this is set to true, a user agent field is required in the table. It should be a varchar 255 like so:
CREATE TABLE sessions ( id INTEGER PRIMARY KEY AUTO_INCREMENT, user_id INTEGER NOT NULL UNIQUE, session_id VARCHAR(255) NOT NULL UNIQUE, user_agent VARCHAR(255), expires INTEGER NOT NULL );
See "user_agent_field" to change the default name of the field.
A session id will only be valid from the ip address it was originally created from. If invalid, the session will be deleted in storage. If this is set to true, an ip address field is required in the table. It should be a varchar 255 like so:
CREATE TABLE sessions ( id INTEGER PRIMARY KEY AUTO_INCREMENT, user_id INTEGER NOT NULL UNIQUE, session_id VARCHAR(255) NOT NULL UNIQUE, ip_address VARCHAR(255), expires INTEGER NOT NULL );
See "ip_address_field" to change the default name of the field.
Sets the Web::Authenticate::Digest::Role that is used for user agents if "require_same_user_agent" is set to true or ip addresses if "require_same_ip_address" is set to true. Default is Web::Authenticate::Digest.
Sets the object that does Web::Authenticate::UserAgentProvider::Role. Default is Web::Authenticate::UserAgentProvider::EnvUserAgentProvider.
Sets the object that does Web::Authenticate::IpAddressProvider::Role. Default is Web::Authenticate::IpAddressProvider::EnvIpAdderssProvider.
Sets the name of the user agent field if "require_same_user_agent" is set to 1. Default is 'user_agent'.
Sets the name of the ip address field if "require_same_ip_address" is set to 1. Default is 'ip_address'.
Sets the name of the expires time field that will be used when querying the database. Default is 'expires'.
Sets the DBIx::Raw object that will be used to query the database. This is required with no default.
The columns to select. At a minimum, "session_id_field", "user_id_field", and "expires_field" will always be selected.
$storage_handler->columns([qw/session_data/]);
Default is an empty array ref.
This is a subroutine reference to the digest hex that will be used when storing the session id. Default is Digest::SHA::sha512_hex.
Takes in user, session_id, expires, and any additional values for columns in a hash and a session with those values is created. Returns a Web::Authenticate::Session with any values from "columns" stored in "row" in Web::Authenticate::Session.
my $session_values => { session_data => $session_data, }; my $session = $session_storage_handler->store_session($user, $session_id, $expires, $session_values); # if you need no extra user values in the row my $session = $storage_handler->store_session($user, $session_id, $expires);
Loads a Web::Authenticate::Session by session_id. If the session exists, the session is returned. Otherwise, undef is returned. Undef will also be returned if the session is expires, or if the user agent or ip address don't match if "require_same_user_agent" or "require_same_ip_address" are set. Any additional "columns" will be stored in "row" in Web::Authenticate::Session.
my $session = $session_storage_handler->load_session($session_id);
Deletes a session from storage.
$session_storage_handler->delete_session($session_id);
Invalidates (deletes) any user sessions for user.
$session_storage_handler->invalidate_user_sessions($user);
Updates the expires time for the session with the session id session_id.
$session_storage_handler->update_expires($session_id, $expires);
Adam Hopkins <srchulo@cpan.org>
This software is copyright (c) 2017 by Adam Hopkins.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install Web::Authenticate, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Web::Authenticate
CPAN shell
perl -MCPAN -e shell install Web::Authenticate
For more information on module installation, please visit the detailed CPAN module installation guide.