fix npm run build
This commit is contained in:
@@ -7,7 +7,7 @@ import { PrismaService } from '../../shared/prisma.service';
|
||||
import { RedisPkceStore } from './pkce/redis-pkce.store';
|
||||
import { InMemoryRefreshStore } from './refresh/inmemory-refresh.store';
|
||||
|
||||
import { Issuer, generators, TokenSet } from 'openid-client';
|
||||
const openidClient: any = require('openid-client');
|
||||
|
||||
@Injectable()
|
||||
export class AuthService {
|
||||
@@ -28,7 +28,7 @@ export class AuthService {
|
||||
if (this.issuer) return this.issuer;
|
||||
const issuerUrl = this.config.get<string>('AUTHENTIK_ISSUER');
|
||||
if (!issuerUrl) throw new Error('AUTHENTIK_ISSUER not configured');
|
||||
this.issuer = await Issuer.discover(issuerUrl);
|
||||
this.issuer = await openidClient.Issuer.discover(issuerUrl);
|
||||
return this.issuer;
|
||||
}
|
||||
|
||||
@@ -47,9 +47,9 @@ export class AuthService {
|
||||
const redirectUri = this.config.get<string>('AUTH_CALLBACK_URL') || `${this.config.get('APP_URL') || ''}/auth/callback`;
|
||||
|
||||
const state = require('crypto').randomUUID();
|
||||
const code_verifier = generators.codeVerifier();
|
||||
const code_challenge = await generators.codeChallenge(code_verifier);
|
||||
const nonce = generators.nonce();
|
||||
const code_verifier = openidClient.generators.codeVerifier();
|
||||
const code_challenge = await openidClient.generators.codeChallenge(code_verifier);
|
||||
const nonce = openidClient.generators.nonce();
|
||||
|
||||
await this.pkceStore.save(state, { code_verifier, nonce, returnTo }, 300);
|
||||
|
||||
@@ -77,7 +77,7 @@ export class AuthService {
|
||||
const redirectUri = this.config.get<string>('AUTH_CALLBACK_URL') || `${this.config.get('APP_URL') || ''}/auth/callback`;
|
||||
|
||||
// exchange code
|
||||
const tokenSet: TokenSet = await client.callback(redirectUri, { code, state }, { code_verifier: pkce.code_verifier, nonce: pkce.nonce });
|
||||
const tokenSet: any = await client.callback(redirectUri, { code, state }, { code_verifier: pkce.code_verifier, nonce: pkce.nonce });
|
||||
|
||||
// verify id_token and get claims
|
||||
const claims = tokenSet.claims();
|
||||
@@ -144,7 +144,7 @@ export class AuthService {
|
||||
|
||||
const userId = data.userId;
|
||||
// load user
|
||||
const domainUser = await this.userRepository.findById(userId);
|
||||
const domainUser = await this.userRepository.getById(userId);
|
||||
if (!domainUser) throw new UnauthorizedException('User not found');
|
||||
if (!domainUser.isActive) throw new UnauthorizedException('User is not active');
|
||||
|
||||
@@ -183,7 +183,7 @@ export class AuthService {
|
||||
if (!token) throw new UnauthorizedException('Missing token');
|
||||
try {
|
||||
const payload: any = this.jwtService.verify(token);
|
||||
const user = await this.userRepository.findById(payload.sub);
|
||||
const user = await this.userRepository.getById(payload.sub);
|
||||
if (!user) throw new UnauthorizedException('User not found');
|
||||
return { id: user.id, username: user.username, email: user.email, roles: user.roles || [] };
|
||||
} catch (e) {
|
||||
|
||||
Reference in New Issue
Block a user