|
|
@ -8,8 +8,9 @@ import { ConfigurationService } from '@ghostfolio/api/services/configuration/con |
|
|
import { PrismaModule } from '@ghostfolio/api/services/prisma/prisma.module'; |
|
|
import { PrismaModule } from '@ghostfolio/api/services/prisma/prisma.module'; |
|
|
import { PropertyModule } from '@ghostfolio/api/services/property/property.module'; |
|
|
import { PropertyModule } from '@ghostfolio/api/services/property/property.module'; |
|
|
|
|
|
|
|
|
import { Module, Logger } from '@nestjs/common'; |
|
|
import { Logger, Module } from '@nestjs/common'; |
|
|
import { JwtModule } from '@nestjs/jwt'; |
|
|
import { JwtModule } from '@nestjs/jwt'; |
|
|
|
|
|
import type { StrategyOptions } from 'passport-openidconnect'; |
|
|
|
|
|
|
|
|
import { ApiKeyStrategy } from './api-key.strategy'; |
|
|
import { ApiKeyStrategy } from './api-key.strategy'; |
|
|
import { AuthController } from './auth.controller'; |
|
|
import { AuthController } from './auth.controller'; |
|
|
@ -45,31 +46,13 @@ import { OidcStrategy } from './oidc.strategy'; |
|
|
configurationService: ConfigurationService |
|
|
configurationService: ConfigurationService |
|
|
) => { |
|
|
) => { |
|
|
const issuer = configurationService.get('OIDC_ISSUER'); |
|
|
const issuer = configurationService.get('OIDC_ISSUER'); |
|
|
const scopeString = configurationService.get('OIDC_SCOPE'); |
|
|
const scope = configurationService.get('OIDC_SCOPE'); |
|
|
const scope = scopeString |
|
|
|
|
|
.split(' ') |
|
|
|
|
|
.map((s) => s.trim()) |
|
|
|
|
|
.filter((s) => s.length > 0); |
|
|
|
|
|
|
|
|
|
|
|
const callbackUrl = |
|
|
const callbackUrl = |
|
|
configurationService.get('OIDC_CALLBACK_URL') || |
|
|
configurationService.get('OIDC_CALLBACK_URL') || |
|
|
`${configurationService.get('ROOT_URL')}/api/auth/oidc/callback`; |
|
|
`${configurationService.get('ROOT_URL')}/api/auth/oidc/callback`; |
|
|
|
|
|
|
|
|
const options: { |
|
|
let options: StrategyOptions; |
|
|
authorizationURL?: string; |
|
|
|
|
|
callbackURL: string; |
|
|
|
|
|
clientID: string; |
|
|
|
|
|
clientSecret: string; |
|
|
|
|
|
issuer?: string; |
|
|
|
|
|
scope: string[]; |
|
|
|
|
|
tokenURL?: string; |
|
|
|
|
|
userInfoURL?: string; |
|
|
|
|
|
} = { |
|
|
|
|
|
callbackURL: callbackUrl, |
|
|
|
|
|
clientID: configurationService.get('OIDC_CLIENT_ID'), |
|
|
|
|
|
clientSecret: configurationService.get('OIDC_CLIENT_SECRET'), |
|
|
|
|
|
scope |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
if (issuer) { |
|
|
if (issuer) { |
|
|
try { |
|
|
try { |
|
|
@ -82,36 +65,36 @@ import { OidcStrategy } from './oidc.strategy'; |
|
|
userinfo_endpoint: string; |
|
|
userinfo_endpoint: string; |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
options.authorizationURL = config.authorization_endpoint; |
|
|
options = { |
|
|
options.issuer = issuer; |
|
|
authorizationURL: config.authorization_endpoint, |
|
|
options.tokenURL = config.token_endpoint; |
|
|
callbackURL: callbackUrl, |
|
|
options.userInfoURL = config.userinfo_endpoint; |
|
|
clientID: configurationService.get('OIDC_CLIENT_ID'), |
|
|
|
|
|
clientSecret: configurationService.get('OIDC_CLIENT_SECRET'), |
|
|
|
|
|
issuer, |
|
|
|
|
|
scope, |
|
|
|
|
|
tokenURL: config.token_endpoint, |
|
|
|
|
|
userInfoURL: config.userinfo_endpoint |
|
|
|
|
|
}; |
|
|
} catch (error) { |
|
|
} catch (error) { |
|
|
Logger.error(error, 'OidcStrategy'); |
|
|
Logger.error(error, 'OidcStrategy'); |
|
|
throw new Error('Failed to fetch OIDC configuration from issuer'); |
|
|
throw new Error('Failed to fetch OIDC configuration from issuer'); |
|
|
} |
|
|
} |
|
|
} else { |
|
|
} else { |
|
|
options.authorizationURL = configurationService.get( |
|
|
options = { |
|
|
'OIDC_AUTHORIZATION_URL' |
|
|
authorizationURL: configurationService.get( |
|
|
); |
|
|
'OIDC_AUTHORIZATION_URL' |
|
|
options.issuer = configurationService.get('OIDC_ISSUER'); |
|
|
), |
|
|
options.tokenURL = configurationService.get('OIDC_TOKEN_URL'); |
|
|
callbackURL: callbackUrl, |
|
|
options.userInfoURL = configurationService.get('OIDC_USER_INFO_URL'); |
|
|
clientID: configurationService.get('OIDC_CLIENT_ID'), |
|
|
|
|
|
clientSecret: configurationService.get('OIDC_CLIENT_SECRET'), |
|
|
|
|
|
issuer: configurationService.get('OIDC_ISSUER'), |
|
|
|
|
|
scope, |
|
|
|
|
|
tokenURL: configurationService.get('OIDC_TOKEN_URL'), |
|
|
|
|
|
userInfoURL: configurationService.get('OIDC_USER_INFO_URL') |
|
|
|
|
|
}; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return new OidcStrategy( |
|
|
return new OidcStrategy(authService, options); |
|
|
authService, |
|
|
|
|
|
options as { |
|
|
|
|
|
authorizationURL: string; |
|
|
|
|
|
callbackURL: string; |
|
|
|
|
|
clientID: string; |
|
|
|
|
|
clientSecret: string; |
|
|
|
|
|
issuer: string; |
|
|
|
|
|
scope: string[]; |
|
|
|
|
|
tokenURL: string; |
|
|
|
|
|
userInfoURL: string; |
|
|
|
|
|
} |
|
|
|
|
|
); |
|
|
|
|
|
}, |
|
|
}, |
|
|
inject: [AuthService, ConfigurationService] |
|
|
inject: [AuthService, ConfigurationService] |
|
|
}, |
|
|
}, |
|
|
|