import { OAuth2UserAdapter, OAuth2User } from '@icynet/oauth2-provider'; import { OAuth2Service } from '../oauth2.service'; import { Request } from 'express'; import { ParamsDictionary } from 'express-serve-static-core'; import { ParsedQs } from 'qs'; export class UserAdapter implements OAuth2UserAdapter { constructor(private _service: OAuth2Service) {} getId(user: OAuth2User): number { return user.id as number; } async fetchById(id: number): Promise { const find = await this._service.userService.getById(id); return { id: find.id, username: find.username, password: find.password, }; } async fetchByUsername(username: string): Promise { const find = await this._service.userService.getByUsername(username); return { id: find.id, username: find.username, password: find.password, }; } checkPassword(user: OAuth2User, password: string): Promise { return this._service.userService.comparePasswords(user.password, password); } async fetchFromRequest( req: Request>, ): Promise { return req.session.user; } async consented( userId: number, clientId: string, scope: string | string[], ): Promise { return false; } async consent( userId: number, clientId: string, scope: string | string[], ): Promise { return true; } }