"""Platform policy review and transport; issuer remains policy authority.""" from html import escape from user_engine.factor_recovery import FactorRecoveryClient class PolicyClient(FactorRecoveryClient): def __init__(self, url): super().__init__(url) self.url = url.rstrip('/') + '/platform/authentication-policy' LABELS = {'mandatory': 'MFA required', 'optional_after_enrollment': 'Optional until an authenticator is activated'} def page(csrf, result=None): result = result or {} def hidden(name, value): return '' common = hidden('csrf_token', csrf) html = '
Choose the sign-in requirement for one reviewed application. Other applications keep their existing policy.
' html += 'Application step-up always wins. An explicit MFA request still requires an authenticator. Portal administration requires MFA; policy changes and lost-factor recovery require recent MFA.
' failure = result.get('failure') if failure: messages = { 'fresh_platform_mfa_required': 'Verify your identity with a fresh MFA sign-in before viewing or changing policy.', 'preview_expired_or_changed': 'The review expired, changed or belongs to another session. Check the current policy and review again.', 'policy_changed_review_again': 'Policy changed after this review. Check the current policy and review again.', 'reference_already_used': 'This reference is already recorded. Check the history; use a new reference for a new change.', 'policy_unchanged': 'The selected policy is already active. No change was made.', 'unsupported_policy': 'This policy or application is unsupported. Choose one of the available policies.', } html += ''+escape(messages.get(failure, 'The policy service is unavailable. Existing policy remains in force. Check the current state before retrying a change.'))+'
' if failure == 'fresh_platform_mfa_required': html += 'Verify with MFA · Set up or recover an authenticator
' if result.get('status') == 'recorded': receipt = result.get('receipt', {}) html += 'Reference: '+escape(str(receipt.get('reference','')))+'. Application: '+escape(str(receipt.get('client','')))+'. Recorded policy: '+escape(LABELS.get(receipt.get('after'), 'Unknown'))+'. Check the current policy below; later changes may supersede this receipt.
' if result.get('status') == 'preview': html += 'Application: '+escape(str(result.get('client','')))+ '. Change from '+escape(LABELS.get(result.get('before'),'Unknown'))+' to '+escape(LABELS.get(result.get('after'),'Unknown'))+'.
' if result.get('after') == 'mandatory': html += 'People without a confirmed working authenticator will be unable to complete sign-in. Verify enrollment and a recovery route before applying. This preview does not count unenrolled users.
' else: html += 'People with no confirmed authenticator can sign in with their password. Once an authenticator is activated, MFA is required. Pending or cancelled setup does not activate MFA; provider lookup failures deny sign-in.
' html += 'This affects subsequent authorization requests. It does not revoke already issued tokens or change another application. Rollback restores the previous policy through another reviewed change.
' html += 'Current policy: '+escape(LABELS.get(client.get('mode'),'Unknown'))+'. Revision '+escape(str(result.get('revision','unknown')))+'.
' html += '