mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-05-10 12:25:02 +00:00
Refresh dashboard authentication on every API call and every 15 minutes
This commit is contained in:
parent
553fb57c46
commit
f3a90faaa7
4 changed files with 63 additions and 5 deletions
|
@ -5,7 +5,9 @@ import crypto from "crypto";
|
|||
import moment from "moment-timezone";
|
||||
// tslint:disable-next-line:no-submodule-imports
|
||||
import uuidv4 from "uuid/v4";
|
||||
import { DBDateFormat } from "../utils";
|
||||
import { DAYS, DBDateFormat } from "../utils";
|
||||
|
||||
const LOGIN_EXPIRY_TIME = 1 * DAYS;
|
||||
|
||||
export class ApiLogins extends BaseRepository {
|
||||
private apiLogins: Repository<ApiLogin>;
|
||||
|
@ -68,7 +70,7 @@ export class ApiLogins extends BaseRepository {
|
|||
logged_in_at: moment.utc().format(DBDateFormat),
|
||||
expires_at: moment
|
||||
.utc()
|
||||
.add(1, "day")
|
||||
.add(LOGIN_EXPIRY_TIME, "ms")
|
||||
.format(DBDateFormat),
|
||||
});
|
||||
|
||||
|
@ -86,4 +88,19 @@ export class ApiLogins extends BaseRepository {
|
|||
},
|
||||
);
|
||||
}
|
||||
|
||||
async refreshApiKeyExpiryTime(apiKey) {
|
||||
const [loginId, token] = apiKey.split(".");
|
||||
if (!loginId || !token) return;
|
||||
|
||||
await this.apiLogins.update(
|
||||
{ id: loginId },
|
||||
{
|
||||
expires_at: moment()
|
||||
.utc()
|
||||
.add(LOGIN_EXPIRY_TIME, "ms")
|
||||
.format(DBDateFormat),
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue