feat: init and fork some code from angular-auth-oidc-client
Some checks are pending
Build, Lint & Test Lib / Built, Lint and Test Library (push) Waiting to run
Build, Lint & Test Lib / Angular latest (push) Blocked by required conditions
Build, Lint & Test Lib / Angular latest & Schematics Job (push) Blocked by required conditions
Build, Lint & Test Lib / Angular latest Standalone & Schematics Job (push) Blocked by required conditions
Build, Lint & Test Lib / Angular 16 & RxJs 6 (push) Blocked by required conditions
Build, Lint & Test Lib / Angular V16 (push) Blocked by required conditions
Docs / Build and Deploy Docs Job (push) Waiting to run
Docs / Close Pull Request Job (push) Waiting to run

This commit is contained in:
2025-01-18 01:05:00 +08:00
parent 276d9fbda8
commit 983254164b
201 changed files with 35689 additions and 0 deletions

View File

@@ -0,0 +1,75 @@
import { DOCUMENT } from '../../dom';
import { inject, Injectable } from 'injection-js';
import { OpenIdConfiguration } from '../config/openid-configuration';
import { LoggerService } from '../logging/logger.service';
@Injectable()
export class IFrameService {
private readonly document = inject(DOCUMENT);
private readonly loggerService = inject(LoggerService);
getExistingIFrame(identifier: string): HTMLIFrameElement | null {
const iFrameOnParent = this.getIFrameFromParentWindow(identifier);
if (this.isIFrameElement(iFrameOnParent)) {
return iFrameOnParent;
}
const iFrameOnSelf = this.getIFrameFromWindow(identifier);
if (this.isIFrameElement(iFrameOnSelf)) {
return iFrameOnSelf;
}
return null;
}
addIFrameToWindowBody(
identifier: string,
config: OpenIdConfiguration
): HTMLIFrameElement {
const sessionIframe = this.document.createElement('iframe');
sessionIframe.id = identifier;
sessionIframe.title = identifier;
this.loggerService.logDebug(config, sessionIframe);
sessionIframe.style.display = 'none';
this.document.body.appendChild(sessionIframe);
return sessionIframe;
}
private getIFrameFromParentWindow(
identifier: string
): HTMLIFrameElement | null {
try {
const iFrameElement =
this.document.defaultView?.parent.document.getElementById(identifier);
if (this.isIFrameElement(iFrameElement)) {
return iFrameElement;
}
return null;
} catch (e) {
return null;
}
}
private getIFrameFromWindow(identifier: string): HTMLIFrameElement | null {
const iFrameElement = this.document.getElementById(identifier);
if (this.isIFrameElement(iFrameElement)) {
return iFrameElement;
}
return null;
}
private isIFrameElement(
element: HTMLElement | null | undefined
): element is HTMLIFrameElement {
return !!element && element instanceof HTMLIFrameElement;
}
}