From 5c185edc5fe24aba44588cfb3afec94e4a2628e6 Mon Sep 17 00:00:00 2001
From: Guillaume Rousse <guillaume.rousse@renater.fr>
Date: Fri, 3 Aug 2018 14:11:37 +0200
Subject: [PATCH] rename token attribute from 'token' to 'secret'

---
 lib/AccountManager/App.pm   | 22 +++++++++++-----------
 lib/AccountManager/Token.pm |  6 +++---
 2 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/lib/AccountManager/App.pm b/lib/AccountManager/App.pm
index b805e5e..e502773 100644
--- a/lib/AccountManager/App.pm
+++ b/lib/AccountManager/App.pm
@@ -454,7 +454,7 @@ sub req_complete_challenge {
         sp_entityid     => $entityid,
         creation_date   => DateTime->now(),
         expiration_date => DateTime->now()->add(hours => $validity_period),
-        token           => AccountManager::Tools::generate_secret(20)
+        secret          => AccountManager::Tools::generate_secret(20)
     );
 
     $self->abort(
@@ -477,7 +477,7 @@ sub req_complete_challenge {
         sourceip  => $ENV{REMOTE_ADDR},
         to        => $email,
         entityid  => $entityid,
-        token     => $token->token(),
+        token     => $token->secret(),
         challenge_url => sprintf(
             '%s&action=complete_challenge&federation=%s&entity=%s&email=%s',
             $self->{configuration}->{app}->{url},
@@ -535,7 +535,7 @@ sub req_complete_challenge {
         "Token send to %s for entityid=%s;token=%s",
         $email,
         $entityid,
-        $token->token(),
+        $token->secret(),
     );
 
     $self->respond(
@@ -575,8 +575,8 @@ sub req_create_accounts {
     ) if !$email;
 
     my $token = AccountManager::Token->new(
-        db    => $self->{db},
-        token => $token_secret
+        db     => $self->{db},
+        secret => $token_secret
     );
 
     $self->abort(
@@ -622,7 +622,7 @@ sub req_create_accounts {
         sp_entityid     => $entityid,
         creation_date   => DateTime->now(),
         expiration_date => DateTime->now()->add(hours => $validity_period),
-        token           => AccountManager::Tools::generate_secret(20)
+        secret          => AccountManager::Tools::generate_secret(20)
     );
 
     $self->abort(
@@ -642,7 +642,7 @@ sub req_create_accounts {
             password        => $password,
             password_crypt  => AccountManager::Tools::encrypt($password, $key),
             password_hash   => AccountManager::Tools::sha256_hash($password),
-            token           => $download_token->token(),
+            token           => $download_token->secret(),
             creation_date   => DateTime->now(),
             expiration_date => DateTime->now()->add(days => $validity_period)
         );
@@ -690,7 +690,7 @@ sub req_create_accounts {
             entityid => $entityid,
             email    => $email,
             key      => $key,
-            token    => $download_token->token(),
+            token    => $download_token->secret(),
             days     => $validity_period,
         }
     );
@@ -722,8 +722,8 @@ sub req_download_accounts {
     ) if !$key;
 
     my $token = AccountManager::Token->new(
-        db    => $self->{db},
-        token => $token_secret
+        db     => $self->{db},
+        secret => $token_secret
     );
 
     $self->abort(
@@ -756,7 +756,7 @@ sub req_download_accounts {
     my $accounts = AccountManager::Account->get_accounts(
         db    => $self->{db},
         query => [
-            token => $self->{in}->{token}
+            token => $token_secret
         ],
     );
 
diff --git a/lib/AccountManager/Token.pm b/lib/AccountManager/Token.pm
index a7427c4..430fab0 100644
--- a/lib/AccountManager/Token.pm
+++ b/lib/AccountManager/Token.pm
@@ -12,7 +12,7 @@ __PACKAGE__->meta->setup(
 
     columns => [
         id              => { type => 'bigserial', not_null => 1 },
-        token           => { type => 'varchar', length => 50, not_null => 1 },
+        token           => { type => 'varchar', length => 50, not_null => 1, alias => 'secret' },
         email_address   => { type => 'varchar', length => 200, not_null => 1 },
         sp_entityid     => { type => 'varchar', length => 200, not_null => 1 },
         creation_date   => { type => 'datetime' },
@@ -34,9 +34,9 @@ sub print {
     $fd = \*STDOUT unless $fd;
 
     printf $fd
-        "Token ID=%s; token=%s; email_address=%s; sp_entityid=%s; creation_date=%s; expiration_date=%s\n",
+        "Token ID=%s; secret=%s; email_address=%s; sp_entityid=%s; creation_date=%s; expiration_date=%s\n",
         $self->id(),
-        $self->token(),
+        $self->secret(),
         $self->email_address(),
         $self->sp_entityid(),
         $self->creation_date()->strftime('%Y:%m:%d %H:%M'),
-- 
GitLab