apim-developer-portal4
Version:
API management developer portal
79 lines (65 loc) • 2.2 kB
text/typescript
import * as ko from "knockout";
import template from "./signin-aad.html";
import { EventManager } from "@paperbits/common/events";
import { Component, RuntimeComponent, Param } from "@paperbits/common/ko/decorators";
import { ValidationReport } from "../../../../../contracts/validationReport";
import { AadService } from "../../../../../services";
export class SignInAad {
constructor(
private readonly aadService: AadService,
private readonly eventManager: EventManager
) {
this.clientId = ko.observable();
this.authority = ko.observable();
this.signinTenant = ko.observable();
this.classNames = ko.observable();
this.label = ko.observable();
}
public clientId: ko.Observable<string>;
public authority: ko.Observable<string>;
public signinTenant: ko.Observable<string>;
public classNames: ko.Observable<string>;
public label: ko.Observable<string>;
/**
* Initiates signing-in with Azure Active Directory.
*/
public async signIn(): Promise<void> {
this.cleanValidationErrors();
try {
await this.aadService.signInWithAadAdal(this.clientId(), this.authority(), this.signinTenant());
}
catch (error) {
let errorDetails;
if (error.code === "ValidationError") {
errorDetails = error.details?.map(detail => detail.message);
}
else {
errorDetails = [error.message];
}
const validationReport: ValidationReport = {
source: "socialAcc",
errors: errorDetails
};
this.eventManager.dispatchEvent("onValidationErrors", validationReport);
}
}
private cleanValidationErrors(): void {
const validationReport: ValidationReport = {
source: "signInOAuth",
errors: []
};
this.eventManager.dispatchEvent("onValidationErrors", validationReport);
}
}