|
|
@ -1,36 +1,49 @@ |
|
|
import { Injectable, Logger } from '@nestjs/common'; |
|
|
import { Injectable, Logger } from '@nestjs/common'; |
|
|
import { PassportStrategy } from '@nestjs/passport'; |
|
|
import { PassportStrategy } from '@nestjs/passport'; |
|
|
import { Provider } from '@prisma/client'; |
|
|
import { Provider } from '@prisma/client'; |
|
|
|
|
|
import { Request } from 'express'; |
|
|
import { Strategy } from 'passport-openidconnect'; |
|
|
import { Strategy } from 'passport-openidconnect'; |
|
|
|
|
|
|
|
|
import { AuthService } from './auth.service'; |
|
|
import { AuthService } from './auth.service'; |
|
|
import { OidcStateStore } from './oidc-state.store'; |
|
|
import { OidcStateStore } from './oidc-state.store'; |
|
|
|
|
|
|
|
|
|
|
|
interface OidcStrategyOptions { |
|
|
|
|
|
authorizationURL?: string; |
|
|
|
|
|
callbackURL: string; |
|
|
|
|
|
clientID: string; |
|
|
|
|
|
clientSecret: string; |
|
|
|
|
|
issuer?: string; |
|
|
|
|
|
scope?: string[]; |
|
|
|
|
|
tokenURL?: string; |
|
|
|
|
|
userInfoURL?: string; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
@Injectable() |
|
|
@Injectable() |
|
|
export class OidcStrategy extends PassportStrategy(Strategy, 'oidc') { |
|
|
export class OidcStrategy extends PassportStrategy(Strategy, 'oidc') { |
|
|
private static readonly stateStore = new OidcStateStore(); |
|
|
private static readonly stateStore = new OidcStateStore(); |
|
|
|
|
|
|
|
|
public constructor( |
|
|
public constructor( |
|
|
private readonly authService: AuthService, |
|
|
private readonly authService: AuthService, |
|
|
options: any |
|
|
options: OidcStrategyOptions |
|
|
) { |
|
|
) { |
|
|
super({ |
|
|
super({ |
|
|
...options, |
|
|
...options, |
|
|
passReqToCallback: true, |
|
|
passReqToCallback: true, |
|
|
scope: ['openid', 'profile', 'email'], |
|
|
scope: ['openid', 'profile', 'email'], |
|
|
store: OidcStrategy.stateStore |
|
|
store: OidcStrategy.stateStore |
|
|
}); |
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
|
|
|
|
} as any); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public async validate( |
|
|
public async validate( |
|
|
_request: any, |
|
|
_request: Request, |
|
|
_issuer: string, |
|
|
_issuer: string, |
|
|
profile: any, |
|
|
profile: { id?: string }, |
|
|
context: any, |
|
|
context: { claims?: { sub?: string } }, |
|
|
idToken: any, |
|
|
idToken: { sub?: string }, |
|
|
_accessToken: any, |
|
|
_accessToken: string, |
|
|
_refreshToken: any, |
|
|
_refreshToken: string, |
|
|
params: any |
|
|
params: { sub?: string } |
|
|
) { |
|
|
) { |
|
|
try { |
|
|
try { |
|
|
const thirdPartyId = |
|
|
const thirdPartyId = |
|
|
|