@idea-ionic/auth
Version:
361 lines (345 loc) • 12.9 kB
TypeScript
import { Routes } from '@angular/router';
import { CognitoUser } from 'amazon-cognito-identity-js';
import { IDEATranslationsService, IDEAStorageService } from '@idea-ionic/common';
import * as i0 from '@angular/core';
import { OnInit, EventEmitter } from '@angular/core';
declare const routes: Routes;
/**
* Cognito wrapper to manage the authentication flow.
*
* Note: in IDEA's Cognito users pools, the email is an alias of the username.
*/
declare class IDEAAuthService {
protected _env: any;
protected _translate: IDEATranslationsService;
protected _storage: IDEAStorageService;
/**
* The name of the Cognito's user attribute which contains the key of the last device to login in this project.
*/
protected deviceKeyAttribute: string;
private userPool;
challengeUsername: string;
private challengePassword;
private newAccountJustRegistered;
private mfaProjectName;
private passwordPolicy;
constructor();
/**
* Prepare the necessary structure to get authorized in Cognito.
*/
private prepareAuthDetails;
/**
* Prepare the necessary structure to identify a Cognito user.
*/
prepareCognitoUser(username: string): CognitoUser;
/**
* Prepare a user attribute (they are all strings) in Cognito's format.
*/
private prepareUserAttribute;
/**
* Perform a login through username and password.
*/
login(username: string, password: string): Promise<LoginOutcomeActions>;
/**
* Complete the new password flow in the authentication.
*/
confirmNewPassword(newPassword: string): Promise<void>;
/**
* Complete the MFA challenge flow in the authentication.
*/
completeMFAChallenge(otpCode: string): Promise<void>;
/**
* Register a new user a set its default attributes.
*/
register(username: string, password: string, attributes?: any): Promise<CognitoUser>;
/**
* In case a new account has just been registered, return the username.
*/
getNewAccountJustRegistered(): string;
/**
* Confirm a new registration through the confirmation code sent by Cognito.
*/
confirmRegistration(username: string, code: string): Promise<void>;
/**
* Send again a confirmation code for a new registration.
*/
resendConfirmationCode(username: string): Promise<void>;
/**
* Logout the currently signed-in user.
*/
logout(options?: {
global: boolean;
}): Promise<void>;
/**
* Send a password reset request.
*/
forgotPassword(username: string): Promise<void>;
/**
* Confirm a new password after a password reset request.
*/
confirmPassword(username: string, code: string, newPwd: string): Promise<void>;
/**
* Gets the URL for enabling MFA. This URL can be used to generate a QR Code to read with an authenticator app.
*/
getURLForEnablingMFA(): Promise<string>;
/**
* Check whether the user has MFA enabled.
*/
checkIfUserHasMFAEnabled(bypassCache?: boolean): Promise<boolean>;
/**
* Configure a MFA device for the user.
*/
private setMFADevice;
/**
* Enable a new MFA device for the user by inserting an OTP code generated by it.
*/
enableMFA(otp: string, mfaDeviceName?: string): Promise<void>;
/**
* Disable MFA for a user by inserting an OTP code generated by it.
*/
disableMFA(otp: string, mfaDeviceName?: string): Promise<void>;
/**
* Check if a user is currently authenticated.
* @param offlineAllowed if set and if offline, skip authentication and retrieve data locally
* @param getFreshIdTokenOnExp cb function to execute when the idToken is refreshed
*/
isAuthenticated(offlineAllowed: boolean, getFreshIdTokenOnExp?: (freshIdToken: string) => void): Promise<any>;
/**
* Helper to refresh the session every N minutes.
*/
private refreshSession;
/**
* Run some post-auth checks, based on the users groups and on the app's configuration:
* - users in the Cognito's "admins" grup skip all the following rules.
* - users in the Cognito's "robots" group can't sign-into front-ends (they serve only back-end purposes).
* - if `env.idea.auth.singleSimultaneousSession` is on, make sure there is only one active session per user.
*/
private runPostAuthChecks;
/**
* Check whether the user signed-into multiple devices.
*/
private checkForSimultaneousSessions;
/**
* Set (or reset) the current user's device (by key) in the current project (stored in Cognito).
*/
private setCurrentDeviceForProject;
/**
* Update the currently logged in user's attributes.
*/
updateUserAttributes(attributes: any): Promise<void>;
/**
* Validate the password against the policy set in the environments configuration.
* In case there are errors, they are returned as an array of strings.
*/
validatePasswordAgainstPolicy(password: string): string[];
/**
* Validate the password against offline and online databases, to avoid common and exploited passwords.
*/
validatePasswordAgainstDatabases(password: string, customStringsToAvoid?: string[]): Promise<string[]>;
/**
* Get a complete password policy pattern, based on the environments configuration, to use on password input fields.
* Note: some of the symbols couldn't be included because unsupported by the input[pattern] attribute.
*/
getPasswordPolicyPatternForInput(): string;
static ɵfac: i0.ɵɵFactoryDeclaration<IDEAAuthService, never>;
static ɵprov: i0.ɵɵInjectableDeclaration<IDEAAuthService>;
}
/**
* The possible actions following a successful login.
*/
declare enum LoginOutcomeActions {
NONE = "none",
NEW_PASSWORD = "newPassword",
MFA_CHALLENGE = "mfaChallenge",
MFA_SETUP = "mfaSetup"
}
declare class IDEASetupMFAButtonComponent implements OnInit {
private _modal;
private _auth;
/**
* The color of the button.
*/
color: string;
/**
* The fill option for the button.
*/
fill: string;
/**
* Trigger then the MFA setup changes.
*/
change: EventEmitter<boolean>;
isMFAEnabled: boolean;
ngOnInit(): Promise<void>;
openMFAModal(): Promise<void>;
static ɵfac: i0.ɵɵFactoryDeclaration<IDEASetupMFAButtonComponent, never>;
static ɵcmp: i0.ɵɵComponentDeclaration<IDEASetupMFAButtonComponent, "idea-setup-mfa-button", never, { "color": { "alias": "color"; "required": false; }; "fill": { "alias": "fill"; "required": false; }; }, { "change": "change"; }, never, never, true, never>;
}
declare class IDEASetupMFAModalComponent implements OnInit {
private _modal;
private _loading;
private _message;
private _auth;
otpCode: string;
isMFAEnabled: boolean;
ngOnInit(): Promise<void>;
private generateQRCodeCanvasByURL;
setMFA(enable: boolean): Promise<void>;
close(): void;
static ɵfac: i0.ɵɵFactoryDeclaration<IDEASetupMFAModalComponent, never>;
static ɵcmp: i0.ɵɵComponentDeclaration<IDEASetupMFAModalComponent, "idea-setup-mfa-modal", never, {}, {}, never, never, true, never>;
}
declare const COMMON_PASSWORDS_TOP_1000: string[];
declare class IDEAConfirmPasswordPage implements OnInit {
protected _env: any;
private _nav;
private _route;
private _popover;
private _message;
private _loading;
private _translate;
_auth: IDEAAuthService;
email: string;
newPassword: string;
code: string;
passwordPolicy: any;
errorMsg: string;
constructor();
ngOnInit(): void;
confirmPassword(): Promise<void>;
openPasswordPolicy(event: Event): Promise<void>;
goToForgotPassword(): void;
goToAuth(): void;
static ɵfac: i0.ɵɵFactoryDeclaration<IDEAConfirmPasswordPage, never>;
static ɵcmp: i0.ɵɵComponentDeclaration<IDEAConfirmPasswordPage, "idea-confirm-password", never, {}, {}, never, never, true, never>;
}
declare class IDEAForgotPasswordPage {
private _nav;
private _message;
private _loading;
private _auth;
email: string;
forgotPassword(): Promise<void>;
goToConfirmPassword(): void;
goToAuth(): void;
static ɵfac: i0.ɵɵFactoryDeclaration<IDEAForgotPasswordPage, never>;
static ɵcmp: i0.ɵɵComponentDeclaration<IDEAForgotPasswordPage, "idea-forgot-password", never, {}, {}, never, never, true, never>;
}
declare class IDEAMFAChallengePage implements OnInit {
private _nav;
private _message;
private _loading;
private _auth;
private _translate;
otpCode: string;
errorMsg: string;
ngOnInit(): void;
completeMFAChallenge(): Promise<void>;
goToAuth(): void;
static ɵfac: i0.ɵɵFactoryDeclaration<IDEAMFAChallengePage, never>;
static ɵcmp: i0.ɵɵComponentDeclaration<IDEAMFAChallengePage, "idea-mfa-challenge", never, {}, {}, never, never, true, never>;
}
declare class IDEANewPasswordPage implements OnInit {
protected _env: any;
private _nav;
private _popover;
private _message;
private _loading;
private _translate;
_auth: IDEAAuthService;
newPassword: string;
passwordPolicy: any;
errorMsg: string;
constructor();
ngOnInit(): void;
confirmNewPassword(): Promise<void>;
openPasswordPolicy(event: Event): Promise<void>;
goToAuth(): void;
static ɵfac: i0.ɵɵFactoryDeclaration<IDEANewPasswordPage, never>;
static ɵcmp: i0.ɵɵComponentDeclaration<IDEANewPasswordPage, "idea-new-password", never, {}, {}, never, never, true, never>;
}
declare class IDEAPasswordPolicyComponent {
protected _env: any;
passwordPolicy: any;
constructor();
static ɵfac: i0.ɵɵFactoryDeclaration<IDEAPasswordPolicyComponent, never>;
static ɵcmp: i0.ɵɵComponentDeclaration<IDEAPasswordPolicyComponent, "idea-password-policy", never, {}, {}, never, never, true, never>;
}
declare class IDEAResendLinkPage {
private _nav;
private _message;
private _loading;
private _auth;
private _translate;
email: string;
errorMsg: string;
resendConfirmationLink(): Promise<void>;
goToAuth(): void;
static ɵfac: i0.ɵɵFactoryDeclaration<IDEAResendLinkPage, never>;
static ɵcmp: i0.ɵɵComponentDeclaration<IDEAResendLinkPage, "idea-resend-link", never, {}, {}, never, never, true, never>;
}
declare class IDEASetupMFAPage {
private _nav;
reloadApp(): void;
goToAuth(): void;
static ɵfac: i0.ɵɵFactoryDeclaration<IDEASetupMFAPage, never>;
static ɵcmp: i0.ɵɵComponentDeclaration<IDEASetupMFAPage, "idea-mfa-setup", never, {}, {}, never, never, true, never>;
}
declare class IDEASignInPage {
protected _env: any;
private _nav;
private _message;
private _loading;
private _translate;
private _auth;
title: string;
registrationPossible: boolean;
hasIntroPage: boolean;
website: string;
externalProviders: {
type: string;
name: string;
emailDomains: string[];
}[];
doneExternalProviderCheck: boolean;
email: string;
password: string;
agreementsCheck: boolean;
newAccountRegistered: boolean;
errorMsg: string;
darkMode: boolean;
constructor();
ionViewDidEnter(): void;
login(): Promise<void>;
checkForExternalProviderEmail(): void;
goToIntro(): void;
goToForgotPassword(): void;
goToRegistration(): void;
translationExists(key: string): boolean;
openLink(url: string): Promise<void>;
static ɵfac: i0.ɵɵFactoryDeclaration<IDEASignInPage, never>;
static ɵcmp: i0.ɵɵComponentDeclaration<IDEASignInPage, "idea-sign-in", never, {}, {}, never, never, true, never>;
}
declare class IDEASignUpPage implements OnInit {
protected _env: any;
private _nav;
private _popover;
private _message;
private _loading;
private _translate;
_auth: IDEAAuthService;
email: string;
password: string;
agreementsCheck: boolean;
passwordPolicy: any;
errorMsg: string;
constructor();
ngOnInit(): void;
register(): Promise<void>;
translationExists(key: string): boolean;
openPasswordPolicy(event: Event): Promise<void>;
goToResendLink(): void;
goToAuth(): void;
static ɵfac: i0.ɵɵFactoryDeclaration<IDEASignUpPage, never>;
static ɵcmp: i0.ɵɵComponentDeclaration<IDEASignUpPage, "idea-sign-up", never, {}, {}, never, never, true, never>;
}
export { COMMON_PASSWORDS_TOP_1000, IDEAAuthService, IDEAConfirmPasswordPage, IDEAForgotPasswordPage, IDEAMFAChallengePage, IDEANewPasswordPage, IDEAPasswordPolicyComponent, IDEAResendLinkPage, IDEASetupMFAButtonComponent, IDEASetupMFAModalComponent, IDEASetupMFAPage, IDEASignInPage, IDEASignUpPage, LoginOutcomeActions, routes };