Automatically renew token when znc responds with a token expired error

This commit is contained in:
Samuel Elliott
2022-05-30 12:31:31 +01:00
parent e48fba254c
commit b8f9c2c110
8 changed files with 91 additions and 58 deletions

View File

@@ -10,6 +10,7 @@ import { ArgumentsCamelCase, Argv, YargsArguments } from '../../util/yargs.js';
import { initStorage } from '../../util/storage.js';
import { getToken, SavedToken } from '../../common/auth/nso.js';
import { NotificationManager, ZncNotifications } from '../../common/notify.js';
import { AuthPolicy, AuthToken, ZncPresenceEventStreamEvent } from '../../api/znc-proxy.js';
declare global {
namespace Express {
@@ -24,26 +25,6 @@ declare global {
}
}
export interface AuthToken {
user: string;
policy?: AuthPolicy;
created_at: number;
}
export interface AuthPolicy {
announcements?: boolean;
list_friends?: boolean;
list_friends_presence?: boolean;
friend?: boolean;
friend_presence?: boolean;
webservices?: boolean;
activeevent?: boolean;
current_user?: boolean;
current_user_presence?: boolean;
friends?: string[];
friends_presence?: string[];
}
const debug = createDebug('cli:nso:http-server');
export const command = 'http-server';
@@ -682,13 +663,6 @@ export async function handler(argv: ArgumentsCamelCase<Arguments>) {
}
}
export enum ZncPresenceEventStreamEvent {
FRIEND_ONLINE = '0',
FRIEND_OFFLINE = '1',
FRIEND_TITLE_CHANGE = '2',
FRIEND_TITLE_STATECHANGE = '3',
}
class EventStreamNotificationManager extends NotificationManager {
constructor(
public req: express.Request,

View File

@@ -3,7 +3,7 @@ import fetch from 'node-fetch';
import Table from '../util/table.js';
import type { Arguments as ParentArguments } from '../nso.js';
import { getToken } from '../../common/auth/nso.js';
import { AuthPolicy, AuthToken } from './http-server.js';
import { AuthPolicy, AuthToken } from '../../api/znc-proxy.js';
import { Argv } from '../../util/yargs.js';
import { initStorage } from '../../util/storage.js';