Skip to content

Feat/enhanced login #789

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
May 9, 2025
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 68 additions & 2 deletions backend/compact-connect/common_constructs/user_pool.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import base64
from collections.abc import Mapping

from aws_cdk import CfnOutput, Duration, RemovalPolicy
Expand All @@ -6,12 +7,14 @@
AdvancedSecurityMode,
AuthFlow,
AutoVerifiedAttrs,
CfnManagedLoginBranding,
CfnUserPoolRiskConfigurationAttachment,
ClientAttributes,
CognitoDomainOptions,
DeviceTracking,
FeaturePlan,
ICustomAttribute,
ManagedLoginVersion,
Mfa,
MfaSecondFactor,
OAuthFlows,
Expand All @@ -20,6 +23,7 @@
PasswordPolicy,
SignInAliases,
StandardAttributes,
UserPoolClient,
UserPoolEmail,
)
from aws_cdk.aws_cognito import UserPool as CdkUserPool
Expand Down Expand Up @@ -83,7 +87,9 @@ def __init__( # pylint: disable=too-many-arguments

if cognito_domain_prefix:
self.user_pool_domain = self.add_domain(
f'{construct_id}Domain', cognito_domain=CognitoDomainOptions(domain_prefix=cognito_domain_prefix)
f'{construct_id}Domain',
cognito_domain=CognitoDomainOptions(domain_prefix=cognito_domain_prefix),
managed_login_version=ManagedLoginVersion.NEWER_MANAGED_LOGIN
)

CfnOutput(self, f'{construct_id}UsersDomain', value=self.user_pool_domain.domain_name)
Expand Down Expand Up @@ -124,7 +130,7 @@ def add_ui_client(
environment_context: dict,
read_attributes: ClientAttributes,
write_attributes: ClientAttributes,
ui_scopes: list[OAuthScope] = None,
ui_scopes: list[OAuthScope] = None
):
"""
Creates an app client for the UI to authenticate with the user pool.
Expand Down Expand Up @@ -222,3 +228,63 @@ def _add_risk_configuration(self, security_profile: SecurityProfile):
)
),
)

def add_managed_login_styles(
self,
user_pool_client: UserPoolClient,
branding_assets: list[any] = None,
branding_settings: dict = None,
):
# Handle custom styles
login_branding = CfnManagedLoginBranding(self, 'MyCfnManagedLoginBranding',
user_pool_id=self.user_pool_id,
assets=branding_assets,
client_id=user_pool_client.user_pool_client_id,
return_merged_resources=False,
settings=branding_settings,
use_cognito_provided_values=False
)

login_branding.add_dependency(user_pool_client.node.default_child)

def prepare_assets_for_managed_login_ui(
self,
ico_filepath: str,
logo_filepath: str,
background_file_path: str | None = None
):

# options found: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-cognito-managedloginbranding-assettype.html#cfn-cognito-managedloginbranding-assettype-category
assets = []
base_64_favicon = self.convert_img_to_base_64(ico_filepath)
assets.append(CfnManagedLoginBranding.AssetTypeProperty(
category='FAVICON_ICO',
color_mode='LIGHT',
extension='ICO',
bytes=base_64_favicon
))

base_64_logo = self.convert_img_to_base_64(logo_filepath)
assets.append(CfnManagedLoginBranding.AssetTypeProperty(
category='FORM_LOGO',
color_mode='LIGHT',
extension='PNG',
bytes=base_64_logo
))

if background_file_path:
base_64_background = self.convert_img_to_base_64(background_file_path)
assets.append(CfnManagedLoginBranding.AssetTypeProperty(
category='PAGE_BACKGROUND',
color_mode='LIGHT',
extension='PNG',
bytes=base_64_background
))

return assets

def convert_img_to_base_64(self, file_path: str):
with open(file_path, 'rb') as binary_file:
binary_file_data = binary_file.read()
base64_encoded_data = base64.b64encode(binary_file_data)
return base64_encoded_data.decode('utf-8')
11 changes: 11 additions & 0 deletions backend/compact-connect/pipeline/backend_stage.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from stacks.persistent_stack import PersistentStack
from stacks.reporting_stack import ReportingStack
from stacks.transaction_monitoring_stack import TransactionMonitoringStack
from stacks.managed_login_stack import ManagedLoginStack


class BackendStage(Stage):
Expand Down Expand Up @@ -35,6 +36,16 @@ def __init__(
environment_name=environment_name,
)

self.managed_login_stack = ManagedLoginStack(
self,
'ManagedLoginStack',
env=environment,
environment_context=environment_context,
environment_name=environment_name,
standard_tags=standard_tags,
persistent_stack=self.persistent_stack,
)

self.ingest_stack = IngestStack(
self,
'IngestStack',
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading