Speakr is a personal, self-hosted web application designed for transcribing audio recordings
Python
Add SSO_DISABLE_PASSWORD_LOGIN option for SSO-only enforcement
Murtaza Nasir1bdb582362d0
diff --git a/README.md b/README.mdindex 0b4a2d62..1059fabf 100644--- a/README.md+++ b/README.md@@ -155,6 +155,7 @@ Complete documentation is available at **[murtaza-nasir.github.io/speakr](https:- **SSO Authentication** - Sign in with any OIDC provider (Keycloak, Azure AD, Google, Auth0, Pocket ID)- **Account Linking/Unlinking** - Link or unlink SSO from Account settings- **Auto-registration** - Optionally create accounts on first SSO login with domain filtering+- **Enforce SSO-only** - Disable password login for regular users (admins retain fallback access)- **Russian Language** - Full Russian translation for the interface*Contributed by [Dmitry Abramov](https://github.com/Daabramov)* | [SSO Setup Guide](https://murtaza-nasir.github.io/speakr/admin-guide/sso-setup/)diff --git a/docs/admin-guide/sso-setup.md b/docs/admin-guide/sso-setup.mdindex 354decdf..665e0cb6 100644--- a/docs/admin-guide/sso-setup.md+++ b/docs/admin-guide/sso-setup.md@@ -24,6 +24,9 @@ SSO_REDIRECT_URI=https://speakr.example.com/auth/sso/callbackSSO_AUTO_REGISTER=trueSSO_ALLOWED_DOMAINS=example.com,company.org+# Disable password login for regular users (optional)+SSO_DISABLE_PASSWORD_LOGIN=false+# Claim mapping (optional)SSO_DEFAULT_USERNAME_CLAIM=preferred_usernameSSO_DEFAULT_NAME_CLAIM=name@@ -81,6 +84,16 @@ Restart Speakr after updating environment variables.- If `SSO_AUTO_REGISTER=false`, only existing users with a linked SSO subject can sign in.- Email domain allowlist is enforced only when an email is present.+## Disabling password login++Set `SSO_DISABLE_PASSWORD_LOGIN=true` to enforce SSO-only authentication for regular users. When enabled:++- The login page shows only the SSO sign-in button+- Regular users cannot log in with email/password+- **Administrators can still use password login** as a fallback (hidden behind "Administrator login" link)++This is useful for organizations that want to enforce SSO for all users while keeping emergency admin access available.+## Security noteWhen a user logs in via SSO with an email that matches an existing Speakr account, the accounts are automatically linked. This is convenient for most setups but relies on trusting your IdP to provide accurate email information.diff --git a/docs/index.md b/docs/index.mdindex 3ffc25fe..9e37a94e 100644--- a/docs/index.md+++ b/docs/index.md@@ -12,6 +12,7 @@ Speakr is a powerful self-hosted transcription platform that helps you capture,- **SSO Authentication** - Sign in with any OIDC provider (Keycloak, Azure AD, Google, Auth0, Pocket ID)- **Account Linking/Unlinking** - Link or unlink SSO from Account settings- **Auto-registration** - Optionally create accounts on first SSO login with domain filtering+ - **Enforce SSO-only** - Disable password login for regular users (admins retain fallback access)- **Russian Language** - Full Russian translation for the interface*Contributed by [Dmitry Abramov](https://github.com/Daabramov)* | [SSO Setup Guide](admin-guide/sso-setup.md)diff --git a/src/api/auth.py b/src/api/auth.pyindex d0f3f037..0250ab23 100644--- a/src/api/auth.py+++ b/src/api/auth.py@@ -143,11 +143,16 @@ def login():if sso_enabled:init_sso_client(current_app)+ password_login_disabled = sso_enabled and sso_config.get('disable_password_login', False)+form = LoginForm()if form.validate_on_submit():user = User.query.filter_by(email=form.email.data).first()if user and user.password:- if bcrypt.check_password_hash(user.password, form.password.data):+ # Check if password login is disabled for non-admins+ if password_login_disabled and not user.is_admin:+ flash('Password login is disabled. Please sign in with SSO.', 'warning')+ elif bcrypt.check_password_hash(user.password, form.password.data):login_user(user, remember=form.remember.data)next_page = request.args.get('next')if not is_safe_url(next_page):@@ -165,7 +170,8 @@ def login():title='Login',form=form,sso_enabled=sso_enabled,- sso_provider_name=sso_config.get('provider_name', 'SSO')+ sso_provider_name=sso_config.get('provider_name', 'SSO'),+ password_login_disabled=password_login_disabled)@@ -389,6 +395,8 @@ def account():init_sso_client(current_app)sso_linked = bool(current_user.sso_subject)+ password_login_disabled = sso_enabled and sso_config.get('disable_password_login', False)+return render_template('account.html',title='Account',default_summary_prompt_text=default_summary_prompt_text,@@ -403,13 +411,21 @@ def account():sso_provider_name=sso_config.get('provider_name', 'SSO'),sso_linked=sso_linked,sso_subject=current_user.sso_subject,- has_password=bool(current_user.password))+ has_password=bool(current_user.password),+ password_login_disabled=password_login_disabled)@auth_bp.route('/change_password', methods=['POST'])@login_required@rate_limit("10 per minute")def change_password():+ # Check if password management is disabled for non-admins+ sso_config = get_sso_config()+ password_login_disabled = is_sso_enabled() and sso_config.get('disable_password_login', False)+ if password_login_disabled and not current_user.is_admin:+ flash('Password management is disabled. Please use SSO to sign in.', 'warning')+ return redirect(url_for('auth.account'))+current_password = request.form.get('current_password')new_password = request.form.get('new_password')confirm_password = request.form.get('confirm_password')diff --git a/src/auth/sso.py b/src/auth/sso.pyindex d28ccd4f..36e56015 100644--- a/src/auth/sso.py+++ b/src/auth/sso.py@@ -29,6 +29,7 @@ def get_sso_config() -> Dict[str, Optional[str]]:"allowed_domains": os.environ.get("SSO_ALLOWED_DOMAINS"),"username_claim": os.environ.get("SSO_DEFAULT_USERNAME_CLAIM", "preferred_username"),"name_claim": os.environ.get("SSO_DEFAULT_NAME_CLAIM", "name"),+ "disable_password_login": _str_to_bool(os.environ.get("SSO_DISABLE_PASSWORD_LOGIN", "false")),}diff --git a/templates/account.html b/templates/account.htmlindex 1c77d625..537d7cbe 100644--- a/templates/account.html+++ b/templates/account.html@@ -621,7 +621,7 @@<i class="fas fa-unlink mr-2"></i> Unlink {{ sso_provider_name }} account</button></form>- {% else %}+ {% elif not password_login_disabled or current_user.is_admin %}<div class="mt-2 text-xs text-[var(--text-muted)]"><i class="fas fa-info-circle mr-1"></i> To unlink SSO, you must first set a password.</div>@@ -644,9 +644,11 @@<a href="{{ url_for('recordings.index') }}" class="inline-flex items-center px-4 py-2 bg-[var(--bg-button)] text-[var(--text-button)] rounded-md hover:bg-[var(--bg-button-hover)] focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-[var(--border-focus)] transition-colors duration-200"><i class="fas fa-microphone mr-2"></i> <span data-i18n="account.goToRecordings">Go to Recordings</span></a>+ {% if not password_login_disabled or current_user.is_admin %}<button id="changePasswordBtn" class="inline-flex items-center px-4 py-2 border border-[var(--border-secondary)] text-[var(--text-secondary)] rounded-md hover:bg-[var(--bg-tertiary)] hover:text-[var(--text-accent)] focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-[var(--border-focus)] transition-colors duration-200"><i class="fas fa-key mr-2"></i> <span data-i18n="account.changePassword">{% if has_password %}Change Password{% else %}Set Password{% endif %}</span></button>+ {% endif %}</div></div></div>@@ -3183,13 +3185,15 @@ curl "https://your-speakr-instance.com/api/recordings?token=YOUR_TOKEN_HERE"</coconst changePasswordForm = document.getElementById('changePasswordForm');const newPasswordInput = document.getElementById('new_password');const confirmPasswordInput = document.getElementById('confirm_password');-- // Open modal- changePasswordBtn.addEventListener('click', () => {- changePasswordModal.classList.remove('hidden');- // Reset form- changePasswordForm.reset();- });++ // Open modal (only if button exists)+ if (changePasswordBtn) {+ changePasswordBtn.addEventListener('click', () => {+ changePasswordModal.classList.remove('hidden');+ // Reset form+ changePasswordForm.reset();+ });+ }// Close modal functionsfunction closeModal() {diff --git a/templates/login.html b/templates/login.htmlindex 5f601c30..69940a02 100644--- a/templates/login.html+++ b/templates/login.html@@ -76,21 +76,42 @@{% endwith %}{% if sso_enabled %}- <div class="flex flex-col space-y-3 mb-6">+ <div class="flex flex-col space-y-3 {% if not password_login_disabled %}mb-6{% endif %}"><a href="{{ url_for('auth.sso_login') }}" class="w-full inline-flex items-center justify-center px-4 py-2 bg-[var(--bg-button)] text-[var(--text-button)] rounded-md hover:bg-[var(--bg-button-hover)] focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-[var(--border-focus)] transition-colors duration-200"><i class="fas fa-cloud mr-2"></i> Sign in with {{ sso_provider_name }}</a>+ {% if not password_login_disabled %}<div class="flex items-center text-xs text-[var(--text-muted)]"><span class="flex-grow border-t border-[var(--border-secondary)]"></span><span class="mx-3 uppercase tracking-wide">or</span><span class="flex-grow border-t border-[var(--border-secondary)]"></span></div>+ {% endif %}</div>{% endif %}+ {% if password_login_disabled %}+ <div class="mt-4 text-center">+ <button type="button" onclick="document.getElementById('admin-login-form').classList.toggle('hidden')" class="text-xs text-[var(--text-muted)] hover:text-[var(--text-secondary)]">+ <i class="fas fa-lock mr-1"></i> Administrator login+ </button>+ </div>+ <form id="admin-login-form" method="POST" action="{{ url_for('auth.login') }}" class="hidden mt-4">+ {{ form.hidden_tag() }}+ <div class="mb-4">+ {{ form.email(class="mt-1 block w-full rounded-md border-[var(--border-secondary)] shadow-sm focus:border-[var(--border-focus)] focus:ring-[var(--ring-focus)] focus:ring-opacity-50 bg-[var(--bg-input)] text-[var(--text-primary)]", placeholder="Admin email") }}+ </div>+ <div class="mb-4">+ {{ form.password(class="mt-1 block w-full rounded-md border-[var(--border-secondary)] shadow-sm focus:border-[var(--border-focus)] focus:ring-[var(--ring-focus)] focus:ring-opacity-50 bg-[var(--bg-input)] text-[var(--text-primary)]", placeholder="Password") }}+ </div>+ <button type="submit" class="w-full py-2 px-4 border border-transparent rounded-md shadow-sm text-sm font-medium text-[var(--text-button)] bg-[var(--bg-button)] hover:bg-[var(--bg-button-hover)] focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-[var(--border-focus)]">+ Sign in+ </button>+ </form>+ {% else %}<form method="POST" action="{{ url_for('auth.login') }}">{{ form.hidden_tag() }}-+<div class="mb-4">{{ form.email.label(class="block text-sm font-medium text-[var(--text-secondary)] mb-1") }}{% if form.email.errors %}@@ -104,7 +125,7 @@{{ form.email(class="mt-1 block w-full rounded-md border-[var(--border-secondary)] shadow-sm focus:border-[var(--border-focus)] focus:ring-[var(--ring-focus)] focus:ring-opacity-50 bg-[var(--bg-input)] text-[var(--text-primary)]") }}{% endif %}</div>-+<div class="mb-6">{{ form.password.label(class="block text-sm font-medium text-[var(--text-secondary)] mb-1") }}{% if form.password.errors %}@@ -118,21 +139,22 @@{{ form.password(class="mt-1 block w-full rounded-md border-[var(--border-secondary)] shadow-sm focus:border-[var(--border-focus)] focus:ring-[var(--ring-focus)] focus:ring-opacity-50 bg-[var(--bg-input)] text-[var(--text-primary)]") }}{% endif %}</div>-+<div class="flex items-center mb-6">{{ form.remember(class="h-4 w-4 text-[var(--text-accent)] focus:ring-[var(--ring-focus)] border-[var(--border-secondary)] rounded") }}{{ form.remember.label(class="ml-2 block text-sm text-[var(--text-secondary)]") }}</div>-+<div class="flex flex-col space-y-4">{{ form.submit(class="w-full py-2 px-4 border border-transparent rounded-md shadow-sm text-sm font-medium text-[var(--text-button)] bg-[var(--bg-button)] hover:bg-[var(--bg-button-hover)] focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-[var(--border-focus)]") }}-+<div class="text-center text-sm text-[var(--text-muted)]"><span>Don't have an account?</span><a href="{{ url_for('auth.register') }}" class="font-medium text-[var(--text-accent)] hover:underline">Register here</a></div></div></form>+ {% endif %}</div></main>