Skip to main content

Login

The Foundation Auth micro front-end (@genesislcap/foundation-auth) provides a comprehensive set of identity-management functions, including authentication (with support for Single Sign-On) and password reset capabilities. Its features are highly customizable, allowing you to enable or disable specific functionalities as needed. Additionally, various elements of the login screen, such as the logo, can be tailored to align with your branding.

The login mechanism uses the Credential Management API for secure credential handling. When the API is unavailable, it seamlessly falls back to using cookies to ensure broad compatibility.

Below are examples showcasing the key screens and functionalities of Foundation Auth. These include the main login interface, authentication via Single Sign-On (SSO), and essential user management features such as password recovery, account creation requests, and password changes.

Main login screenAuthentication via SSOForgotten passwordChange passwordRequest account
Main login screen exampleMain login screen exampleMain login screen exampleMain login screen exampleMain login screen example
info

See complete set of API documentation here

Authentication methods

Authentication is primarily configured on the back end. It's essential to familiarize yourself with the authentication section of the back-end configuration to ensure proper integration.

Username and password

The default authentication method involves the user providing their username and password. Even when Single Sign-On (SSO) is enabled, users will still have the option to sign in using their standard credentials.

info

To streamline development, setting the DEFAULT_USER and DEFAULT_PASSWORD environment variables will pre-populate the login form with these credentials. This can save developers from entering the credentials repeatedly during testing. However, if the browser has previously saved login credentials, it may autofill the form, making this step unnecessary.

Single Sign-On (SSO)

Foundation Auth supports Single Sign-On (SSO) integration, allowing users to authenticate using a unified set of credentials, which may also include credentials from the Genesis Application Platform. Genesis supports SSO with both JWT and SAML.

While setting up SSO is primarily a back-end task, some front-end SSO configuration is required.

info

The standard SSO process involves redirecting users to the authentication provider's flow from the current page. However, many authentication providers block their system when running inside an iframe to prevent clickjacking attacks. To mitigate this, if the auth micro front-end detects it's running within an iframe, it opens the authentication flow in a separate popup window instead.

Integration

Foundation Auth is designed to integrate seamlessly into various application environments, offering flexibility in both basic and advanced use cases. Depending on your platform (Genesis, React, Angular), the integration process may vary slightly. Below, you will find guidance for both basic and advanced usage scenarios, helping you set up the login functionality in your application with ease.

@genesislcap/foundation-auth exposes a single, asynchronous configure() function. It registers the required dependency-injection config and defines the custom element in one step, then resolves with the defined FoundationAuth element class — which makes it a natural fit for a lazily-loaded route element.

Basic usage

This section outlines the steps required to quickly integrate Foundation Auth into your application. The basic setup guide covers the essential configuration for setting up the login form, as well as establishing necessary routes and authentication options.

This example focuses on the setup necessary for enabling authentication functionality in your React application. While it's not a complete routes configuration, it includes all the required elements related to the login setup.

Place the following code in the file where you want to define the auth component, so it can later be imported into your main application file:

info

To see the full login configuration for React, visit the howto-ui-integrations-react.

import { AUTH_PATH } from '../config';
import { history } from '../utils/history';

/**
* Configure the micro frontend
*/
export const configureFoundationAuth = async () => {
const { configure } = await import('@genesislcap/foundation-auth/config');

return configure({
name: `client-app-login`,
hostPath: AUTH_PATH,
postLoginRedirect: () => {
history.push('/order-mgmt');
},
});
};

Advanced usage

For more complex scenarios, the advanced usage section explores how to customize Foundation Auth to meet specific needs. This includes advanced configuration options and extending its functionality for more intricate workflows, such as integrating Single Sign-On (SSO) or adding custom form fields.

The following example uses the Genesis framework. The most important aspect of this example is the configure function, which enables the application of advanced configurations. Notably, this function works the same way for React and Angular frameworks, ensuring consistency across implementations.

name: 'login',
path: 'login',
title: 'Login',
element: async () => {
const { configure, defaultAuthConfig } = await import('@genesislcap/foundation-auth/config');
return configure({
sso: {
toggled: true,
},
omitRoutes: ['request-account'],
fields: {
...defaultAuthConfig.fields,
organisation: {
label: 'CompID',
},
},
hostPath: 'login',
postLoginRedirect: () => {
Route.path.push('dashboard');
},
logo: loginLogo,
background: loginBG,
// Optionally provide a fully custom tag name for the defined element.
name: `nexus-login`,
});
},
layout: loginLayout,
settings: { public: true },
childRouters: true,

Configuration

The configuration section provides detailed information on how to configure and customize Foundation Auth. This section covers the management of public and private routes, as well as the available settings to tailor the authentication process and adjust the login interface to meet the specific requirements of your application.

Public and private routes

You may need to configure a NavigationContributor in your application's router configuration class to manage public and autoAuth route settings:

  • public: Indicates that a route is accessible without requiring user authentication.
  • autoAuth: Automatically logs in users with an active authenticated session when they navigate away from a page and return later.
{
path: 'info',
element: Info,
title: 'Info',
name: 'info',
settings: { public: true },
},
{
path: 'admin',
element: Admin,
title: 'Admin',
name: 'admin',
settings: { autoAuth: true },
}
warning

By default, a route that isn’t explicitly marked as public is considered non-public. However, non-public routes do not automatically block non-authenticated users from accessing them. This behavior must be implemented in a NavigationContributor. For more details, see the example above.

Customization options

Foundation Auth offers extensive customization options to tailor its behavior and appearance to specific application requirements. This can be achieved by using the exported configure function. Through this function, you can modify default settings, such as omitting certain routes, customizing form fields, or providing post-login/post-logout redirect behavior.

Below is a table with the available configuration properties:

AttributeTypeUseExample
backgroundComposableStyles | ComposableStyles[] | nullStyles for the background of the login screen.
background: css`
:host {
background-image: url(${customBGImport});
}
`,
backgroundVideo{ src: string; type: 'video/ogg' | 'video/mp4' | 'video/webm'; } | nullPlays a background video behind the login form instead of a static background.
backgroundVideo: { src: '/assets/login-bg.mp4', type: 'video/mp4' }
feedbackDelaynumber(Optional) Delay, in milliseconds, before transient feedback messages (e.g. forgot/reset password confirmations) are cleared. Defaults to 3000.
feedbackDelay: 5000
fieldsFieldConfigMapConfiguration map for each of the primary form fields.
fields: { 
...defaultAuthConfig.fields,
organisation: {
label: 'CompID'
}
}
hostPathstringThe path of the microfrontend as defined in the parent/host route.
hostPath: 'login'
localizationResourcesI18nextConfig['resources'](Optional) Internationalization (i18n) resources for localization.
localizationResources: {
en: {
translation: {
key: 'Hello World'
}
},
es: {
translation: {
key: 'Hola Mundo'
}
}
}
logoComposableStyles | ComposableStyles[] | nullCustomizable styles for the logo. Providing null will hide the logo.
logo: css`
content: url(${customLogoImport});
`,
logoAltTextstringAlt text for the logo, used for accessibility.
logoAltText: 'Company Logo'
omitRedirectUrlsstring[]Specifies return URLs to omit, which may have been captured by the session service.
omitRedirectUrls: ['/not-found'],
omitRoutesExclude<AuthRoutes, 'login' | 'not-found'>[]Omits specific internal routes, except for login and not-found.
omitRoutes: ['request-account'],
postLoginRedirect() => voidCallback invoked after a successful login, used to hand control back to the host app's router. Defaults to navigating to the user's last path (or protected).
postLoginRedirect: () => navigateToFn('/order-mgmt')
postLogoutRedirect() => voidCallback invoked after logout, used to hand control back to the host app's router.
postLogoutRedirect: () => navigateToFn('/login')
showEnvironmentIndicatorboolean(Optional) Toggles the display of the environment indicator. See Environment Indicator for configuration details.
showEnvironmentIndicator: true
ssoSSOConfig | nullConfigures Single Sign-On (SSO) settings.
sso: {
toggled: true,
},
templateOptionsTemplateOptionsMaps internal subcomponent tags (button, checkbox, provider, etc.) to your host application's design-system elements. Merged with the package's defaultTemplateOptions.
templateOptions: {
button: 'nexus-button',
checkbox: 'nexus-checkbox-next',
provider: 'template',
}
versionInformationstring(Optional) Displays version information for the login microfrontend.
versionInformation: 'Version 1.2.3'
info

AuthConfig also accepts name, attributes, shadowOptions and elementOptions (inherited from FAST's PartialFASTElementDefinition), letting you control the tag name and element definition used when configure() defines the custom element.

Terms and Conditions

The framework supports enabling a Terms and Conditions page that is presented to the user when they login. To enable this functionality add this block to the auth-preferences.kts

    mfa {
termsAndConditions {}
}

Then when the user logs in they will be presented with a Terms and Conditions dialog as shown here:

Terms and Conditions dialog example