mirror of
https://github.com/immich-app/immich.git
synced 2026-05-18 03:10:24 +03:00
chore: use esm global import (#27408)
This commit is contained in:
@@ -1,5 +1,19 @@
|
|||||||
import { Injectable, InternalServerErrorException } from '@nestjs/common';
|
import { Injectable, InternalServerErrorException } from '@nestjs/common';
|
||||||
import type { UserInfoResponse } from 'openid-client' with { 'resolution-mode': 'import' };
|
import {
|
||||||
|
allowInsecureRequests,
|
||||||
|
authorizationCodeGrant,
|
||||||
|
buildAuthorizationUrl,
|
||||||
|
calculatePKCECodeChallenge,
|
||||||
|
ClientSecretBasic,
|
||||||
|
ClientSecretPost,
|
||||||
|
discovery,
|
||||||
|
fetchUserInfo,
|
||||||
|
None,
|
||||||
|
randomPKCECodeVerifier,
|
||||||
|
randomState,
|
||||||
|
skipSubjectCheck,
|
||||||
|
type UserInfoResponse,
|
||||||
|
} from 'openid-client';
|
||||||
import { OAuthTokenEndpointAuthMethod } from 'src/enum';
|
import { OAuthTokenEndpointAuthMethod } from 'src/enum';
|
||||||
import { LoggingRepository } from 'src/repositories/logging.repository';
|
import { LoggingRepository } from 'src/repositories/logging.repository';
|
||||||
|
|
||||||
@@ -24,8 +38,6 @@ export class OAuthRepository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async authorize(config: OAuthConfig, redirectUrl: string, state?: string, codeChallenge?: string) {
|
async authorize(config: OAuthConfig, redirectUrl: string, state?: string, codeChallenge?: string) {
|
||||||
const { buildAuthorizationUrl, randomState, randomPKCECodeVerifier, calculatePKCECodeChallenge } =
|
|
||||||
await import('openid-client');
|
|
||||||
const client = await this.getClient(config);
|
const client = await this.getClient(config);
|
||||||
state ??= randomState();
|
state ??= randomState();
|
||||||
|
|
||||||
@@ -64,7 +76,6 @@ export class OAuthRepository {
|
|||||||
expectedState: string,
|
expectedState: string,
|
||||||
codeVerifier: string,
|
codeVerifier: string,
|
||||||
): Promise<OAuthProfile> {
|
): Promise<OAuthProfile> {
|
||||||
const { authorizationCodeGrant, fetchUserInfo, ...oidc } = await import('openid-client');
|
|
||||||
const client = await this.getClient(config);
|
const client = await this.getClient(config);
|
||||||
const pkceCodeVerifier = client.serverMetadata().supportsPKCE() ? codeVerifier : undefined;
|
const pkceCodeVerifier = client.serverMetadata().supportsPKCE() ? codeVerifier : undefined;
|
||||||
|
|
||||||
@@ -77,7 +88,7 @@ export class OAuthRepository {
|
|||||||
this.logger.debug('Using ID token claims instead of userinfo endpoint');
|
this.logger.debug('Using ID token claims instead of userinfo endpoint');
|
||||||
profile = tokenClaims as OAuthProfile;
|
profile = tokenClaims as OAuthProfile;
|
||||||
} else {
|
} else {
|
||||||
profile = await fetchUserInfo(client, tokens.access_token, oidc.skipSubjectCheck);
|
profile = await fetchUserInfo(client, tokens.access_token, skipSubjectCheck);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!profile.sub) {
|
if (!profile.sub) {
|
||||||
@@ -124,7 +135,6 @@ export class OAuthRepository {
|
|||||||
timeout,
|
timeout,
|
||||||
}: OAuthConfig) {
|
}: OAuthConfig) {
|
||||||
try {
|
try {
|
||||||
const { allowInsecureRequests, discovery } = await import('openid-client');
|
|
||||||
return await discovery(
|
return await discovery(
|
||||||
new URL(issuerUrl),
|
new URL(issuerUrl),
|
||||||
clientId,
|
clientId,
|
||||||
@@ -134,7 +144,7 @@ export class OAuthRepository {
|
|||||||
userinfo_signed_response_alg: profileSigningAlgorithm === 'none' ? undefined : profileSigningAlgorithm,
|
userinfo_signed_response_alg: profileSigningAlgorithm === 'none' ? undefined : profileSigningAlgorithm,
|
||||||
id_token_signed_response_alg: signingAlgorithm,
|
id_token_signed_response_alg: signingAlgorithm,
|
||||||
},
|
},
|
||||||
await this.getTokenAuthMethod(tokenEndpointAuthMethod, clientSecret),
|
this.getTokenAuthMethod(tokenEndpointAuthMethod, clientSecret),
|
||||||
{
|
{
|
||||||
execute: [allowInsecureRequests],
|
execute: [allowInsecureRequests],
|
||||||
timeout,
|
timeout,
|
||||||
@@ -146,9 +156,7 @@ export class OAuthRepository {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async getTokenAuthMethod(tokenEndpointAuthMethod: OAuthTokenEndpointAuthMethod, clientSecret?: string) {
|
private getTokenAuthMethod(tokenEndpointAuthMethod: OAuthTokenEndpointAuthMethod, clientSecret?: string) {
|
||||||
const { None, ClientSecretPost, ClientSecretBasic } = await import('openid-client');
|
|
||||||
|
|
||||||
if (!clientSecret) {
|
if (!clientSecret) {
|
||||||
return None();
|
return None();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user