@@ -26,8 +26,7 @@ public function up(): void
2626
2727 /*
2828 * Auth Identities Table
29- * Used for storage of passwords, reset hashes
30- * social login identities, etc.
29+ * Used for storage of passwords, access tokens, social login identities, etc.
3130 */
3231 $ this ->forge ->addField ([
3332 'id ' => ['type ' => 'int ' , 'constraint ' => 11 , 'unsigned ' => true , 'auto_increment ' => true ],
@@ -49,22 +48,45 @@ public function up(): void
4948 $ this ->forge ->addForeignKey ('user_id ' , 'users ' , 'id ' , '' , 'CASCADE ' );
5049 $ this ->forge ->createTable ('auth_identities ' , true );
5150
52- // Auth Login Attempts Table
51+ /**
52+ * Auth Login Attempts Table
53+ * Records login attempts. A login means users think it is a login.
54+ * To login, users do action(s) like posting a form.
55+ */
5356 $ this ->forge ->addField ([
5457 'id ' => ['type ' => 'int ' , 'constraint ' => 11 , 'unsigned ' => true , 'auto_increment ' => true ],
55- 'ip_address ' => ['type ' => 'varchar ' , 'constraint ' => 255 , ' null ' => true ],
58+ 'ip_address ' => ['type ' => 'varchar ' , 'constraint ' => 255 ],
5659 'user_agent ' => ['type ' => 'varchar ' , 'constraint ' => 255 , 'null ' => true ],
57- 'identifier ' => ['type ' => 'varchar ' , 'constraint ' => 255 , ' null ' => true ],
60+ 'identifier ' => ['type ' => 'varchar ' , 'constraint ' => 255 ],
5861 'user_id ' => ['type ' => 'int ' , 'constraint ' => 11 , 'unsigned ' => true , 'null ' => true ], // Only for successful logins
5962 'date ' => ['type ' => 'datetime ' ],
6063 'success ' => ['type ' => 'tinyint ' , 'constraint ' => 1 ],
6164 ]);
6265 $ this ->forge ->addPrimaryKey ('id ' );
6366 $ this ->forge ->addKey ('identifier ' );
6467 $ this ->forge ->addKey ('user_id ' );
65- // NOTE: Do NOT delete the user_id or email when the user is deleted for security audits
68+ // NOTE: Do NOT delete the user_id or identifier when the user is deleted for security audits
6669 $ this ->forge ->createTable ('auth_logins ' , true );
6770
71+ /*
72+ * Auth Token Login Attempts Table
73+ * Records Bearer Token type login attempts.
74+ */
75+ $ this ->forge ->addField ([
76+ 'id ' => ['type ' => 'int ' , 'constraint ' => 11 , 'unsigned ' => true , 'auto_increment ' => true ],
77+ 'ip_address ' => ['type ' => 'varchar ' , 'constraint ' => 255 ],
78+ 'user_agent ' => ['type ' => 'varchar ' , 'constraint ' => 255 , 'null ' => true ],
79+ 'identifier ' => ['type ' => 'varchar ' , 'constraint ' => 255 ],
80+ 'user_id ' => ['type ' => 'int ' , 'constraint ' => 11 , 'unsigned ' => true , 'null ' => true ], // Only for successful logins
81+ 'date ' => ['type ' => 'datetime ' ],
82+ 'success ' => ['type ' => 'tinyint ' , 'constraint ' => 1 ],
83+ ]);
84+ $ this ->forge ->addPrimaryKey ('id ' );
85+ $ this ->forge ->addKey ('identifier ' );
86+ $ this ->forge ->addKey ('user_id ' );
87+ // NOTE: Do NOT delete the user_id or identifier when the user is deleted for security audits
88+ $ this ->forge ->createTable ('auth_token_logins ' , true );
89+
6890 /*
6991 * Auth Remember Tokens (remember-me) Table
7092 * @see https://paragonie.com/blog/2015/04/secure-authentication-php-with-long-term-persistence
@@ -114,6 +136,7 @@ public function down(): void
114136
115137 $ this ->forge ->dropTable ('users ' , true );
116138 $ this ->forge ->dropTable ('auth_logins ' , true );
139+ $ this ->forge ->dropTable ('auth_token_logins ' , true );
117140 $ this ->forge ->dropTable ('auth_remember_tokens ' , true );
118141 $ this ->forge ->dropTable ('auth_access_tokens ' , true );
119142 $ this ->forge ->dropTable ('auth_identities ' , true );
0 commit comments