refactor(auth): make validate method of strategy use parsed idToken to work with Authentik JWT payload instead of profile
This commit is contained in:
parent
e6c949e40b
commit
5dafef82f2
|
|
@ -49,10 +49,15 @@ export class AuthentikStrategy extends PassportStrategy(OIDCStrategy, 'openidcon
|
||||||
cb: VerifyCallback,
|
cb: VerifyCallback,
|
||||||
): Promise<any> {
|
): Promise<any> {
|
||||||
try {
|
try {
|
||||||
const email = profile.emails?.[0]?.value;
|
|
||||||
if (!email) return cb(new Error('Missing email in OIDC profile'), false);
|
|
||||||
|
|
||||||
const user = await this.authentikAuthService.validateUser(email);
|
|
||||||
|
const components = _idToken.split('.');
|
||||||
|
const payload = Buffer.from(components[1], "base64").toString('utf-8');
|
||||||
|
const claims = JSON.parse(payload);
|
||||||
|
|
||||||
|
if (!claims.email) return cb(new Error('Missing email in OIDC profile'), false);
|
||||||
|
|
||||||
|
const user = await this.authentikAuthService.validateUser(claims.email);
|
||||||
if (!user) return cb(new Error('User not found'), false);
|
if (!user) return cb(new Error('User not found'), false);
|
||||||
|
|
||||||
return cb(null, user);
|
return cb(null, user);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user