Skip to content
Snippets Groups Projects
Commit a5b8d903 authored by Guillaume ROUSSE's avatar Guillaume ROUSSE
Browse files

manage tokens expiration as done for accounts

parent 6febb8b2
No related branches found
No related tags found
No related merge requests found
......@@ -254,8 +254,7 @@ sub list_tokens {
push @{ $args{query} }, token => $options{token};
}
if ($options{expired}) {
push @{ $args{query} }, creation_date =>
{ lt => time - ($configuration->{_}->{tokens_validity_period} * 3600) };
push @{ $args{query} }, expiration_date => { lt => DateTime->now() };
}
my $tokens =
......@@ -325,12 +324,14 @@ sub add_token {
}
# compute a new token
my $validity_period = $configuration->{_}->{tokens_validity_period};
my $token = AccountManager::Token->new(
db => $db,
email_address => $options{email_address},
sp_entityid => $options{sp_entityid},
creation_date => DateTime->today(),
token => AccountManager::Tools::generate_token()
db => $db,
email_address => $options{email_address},
sp_entityid => $options{sp_entityid},
creation_date => DateTime->today(),
expiration_date => DateTime->today()->add(hours => $validity_period),
token => AccountManager::Tools::generate_token()
);
$token->save() or die "failed to save authentication token\n";
......
......@@ -12,6 +12,7 @@ CREATE TABLE `tokens` (
`email_address` varchar(200) NOT NULL,
`sp_entityid` varchar(200) NOT NULL,
`creation_date` date DEFAULT NULL,
`expiration_date` date DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `token_2` (`token`),
KEY `token` (`token`),
......
......@@ -9,11 +9,12 @@ __PACKAGE__->meta->setup(
table => 'tokens',
columns => [
id => { type => 'bigserial', not_null => 1 },
token => { type => 'varchar', length => 50, not_null => 1 },
email_address => { type => 'varchar', length => 200, not_null => 1 },
sp_entityid => { type => 'varchar', length => 200, not_null => 1 },
creation_date => { type => 'date' },
id => { type => 'bigserial', not_null => 1 },
token => { type => 'varchar', length => 50, not_null => 1 },
email_address => { type => 'varchar', length => 200, not_null => 1 },
sp_entityid => { type => 'varchar', length => 200, not_null => 1 },
creation_date => { type => 'date' },
expiration_date => { type => 'date' },
],
primary_key_columns => [ 'id' ],
......@@ -29,12 +30,13 @@ sub print {
$fd = \*STDOUT unless $fd;
printf $fd
"Token ID=%s; token=%s; email_address=%s; sp_entityid=%s; creation_date=%s\n",
"Token ID=%s; token=%s; email_address=%s; sp_entityid=%s; creation_date=%s; expiration_date=%s\n",
$self->id(),
$self->token(),
$self->email_address(),
$self->sp_entityid(),
$self->creation_date()->strftime('%Y:%m:%d');
$self->creation_date()->strftime('%Y:%m:%d'),
$self->expiration_date()->strftime('%Y:%m:%d');
}
1;
......@@ -339,12 +339,15 @@ sub req_generate_token {
}
# compute a new token
my $validity_period =
$self->{configuration}->{_}->{tokens_validity_period};
my $token = AccountManager::Token->new(
db => $self->{db},
email_address => $self->{in}->{email_address},
sp_entityid => $self->{in}->{sp_entityid},
creation_date => DateTime->today(),
token => AccountManager::Tools::generate_token()
db => $self->{db},
email_address => $self->{in}->{email_address},
sp_entityid => $self->{in}->{sp_entityid},
creation_date => DateTime->today(),
expiration_date => DateTime->today()->add(hours => $validity_period),
token => AccountManager::Tools::generate_token()
);
unless ($token->save()) {
......
......@@ -40,6 +40,8 @@ SKIP: {
my $configuration = File::Temp->new(UNLINK => $ENV{TEST_DEBUG} ? 0 : 1);
print {$configuration} <<EOF;
tokens_validity_period = 2
[database]
type = $ENV{TEST_DB_TYPE}
host = $ENV{TEST_DB_HOST}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment