feature/fix-clippy-on-stable-channel
name: smbcloud-auth
description: Use when building, debugging, or extending smbCloud authentication across the Rails auth service, the web console, the Rust or WASM auth SDKs, and Tauri or web client apps. Covers platform clients vs tenant auth apps, AuthUser signup/sign-in/confirmation, OAuth providers for AuthUser, shared auth apps across projects, browser SDK integration, and development vs production app credentials.
smbCloud Auth
Use this skill when work touches any part of the smbCloud auth stack:
smbcloud-apiRails auth servicesmbcloud-web-consoleNext.js admin UIsmbcloud-cli/crates/smbcloud-auth-sdkcanonical client SDK core (wrapped by the-pyand-wasmbindings; the Apple SDK is the native Swift packagesmbcloud-auth-swift, not a UniFFI binding)smbcloud-cli/crates/smbcloud-auth-sdk-wasmbrowser SDK (binding over the core)smbcloud-cli/crates/smbcloud-auththe smbcloud-cli's own internal auth client — NOT the published SDK- Tauri apps such as Rumi Learn Persian and PBJ Komplit
- web apps that use
@smbcloud/sdk-auth
Core model
There are two auth planes. Do not mix them.
1. Platform clients
These are smbCloud's own apps:
webclisigitmoovibewebconsole
They authenticate smbCloud operator users through platform endpoints such as:
POST /v1/users/sign_inPOST /v1/users
They must use the platform client validator, not tenant app validation.
2. Tenant auth apps
These are customer-facing apps such as Rumi or PBJ Komplit.
They authenticate end users through:
POST /v1/client/usersPOST /v1/client/users/sign_inGET /v1/client/meDELETE /v1/client/meDELETE /v1/client/users/sign_outGET /v1/client/users/confirmation
The tenant auth domain is:
AuthAppAuthAppSecretAuthUser
Tenant apps must use AuthAppClientAuthenticatable and must not go through platform /v1/users.
Provider auth boundary
OAuth providers such as Apple or Google for customer apps belong to the tenant auth plane:
- provider sign-in for end users must resolve to
AuthUser - provider linkage must be scoped to
AuthApp - the result must be the same tenant auth session shape used by email/password
Do not route tenant provider auth through:
- platform
User Authorizationrecords for platform users- Doorkeeper/OIDC smbCloud internal users
If provider support is added for tenant apps, the backend contract should end in an AuthUser session or JWT, not a provider token as the primary app session.
Multi-project auth apps
Current rule:
- one
AuthApphas an owner project viaauth_apps.project_id - one
AuthAppcan be shared with other projects throughauth_app_projects - one project can point to only one auth app
If a workspace/project should reuse an existing auth app, attach it instead of creating a duplicate.
Rails conventions
When editing smbcloud-api:
- Platform operator auth stays under
User - Tenant app auth stays under
AuthUser - Do not reuse
OauthApplicationfor tenant end-user login - Do not hardcode tenant app validation in platform controllers
Tenant provider auth modeling
If tenant users need Apple, Google, or other OAuth providers:
- add provider linkage for
AuthUser, not platformUser - model by stable provider subject, not by email
- keep provider records scoped to the tenant auth app
Preferred shape:
AuthUserAuthorizationauth_user_idprovideruid- optional
email - optional
raw_profile
For Apple specifically:
- use Apple
subas the stable provider identity - do not treat email as the primary key
- do not assume name is available after first sign-in
The Rails backend should verify provider assertions and then mint the normal tenant auth session for the resolved AuthUser.
AuthUser signup/sign-in rules
- Signup creates an
AuthUserscoped tocurrent_auth_app - Signup sends confirmation email
- Do not auto-set
confirmed_at - Sign-in returns
EmailNotVerifieduntil email is confirmed - Deletion removes the currently authenticated
AuthUser
Mail flow
For tenant users, use the explicit confirmation flow already established:
- custom mailer for
AuthUser - confirmation link to
/v1/client/users/confirmation?confirmation_token=...
Do not claim email confirmation exists unless the mailer and route are actually wired.
Rust SDK conventions
The canonical Rust client surface lives in:
smbcloud-cli/crates/smbcloud-auth-sdk— the shared SDK core; the published bindings (smbcloud-auth-sdk-py,smbcloud-auth-sdk-wasm) depend on it. Change the client contract here.smbcloud-cli/crates/smbcloud-auth-sdk-wasm— the browser binding (@smbcloud/sdk-auth).- Apple platforms are served by the native Swift port in
smbcloud-auth-swift(AuthCore), pinned to this crate by a conformance suite — there is no UniFFI Apple binding.
smbcloud-cli/crates/smbcloud-auth is the CLI's own internal auth client (only
the cli crate depends on it); don't treat it as the SDK.
When changing tenant app auth:
- keep tenant auth on
/v1/client/* - preserve
AccountStatusmapping:NotFoundReady { access_token }Incomplete { status }
request_logindepends on422+error_codefor incomplete accounts
If the backend changes error shape or status codes, update the Rust parser accordingly.
Browser/WASM SDK conventions
The browser package is consumed as @smbcloud/sdk-auth.
Current exported surface includes:
signup_with_clientlogin_with_clientme_with_clientlogout_with_clientremove_with_clientEnvironment.DevEnvironment.Production
Recommended browser integration pattern:
- lazy-load the WASM runtime with
await import("@smbcloud/sdk-auth") - call
await runtime.default()before using the exported functions - store only the access token in browser storage
- restore the session with
me_with_client - gate environment switching behind explicit debug controls
Do not build browser flows around NextAuth sessions if the product session is actually an smbCloud AuthUser token. The browser app should either:
- use the browser SDK directly for email/password flows, or
- complete provider auth through Rails and then store the resulting tenant auth token
Tauri client conventions
For Rumi/PBJ-style apps:
- use a dedicated
src-tauri/src/smbcloud/mod.rs - expose commands for:
signup_usersign_in_usercurrent_usersign_out_userdelete_current_useris_debug_build
- store auth state in plugin-store:
- access token
- provider
- auth environment
- language
Environment handling
Keep development and production app credentials separate.
Preferred pattern:
- development credentials for local auth service
- production credentials for hosted auth service
- switch via a Rust
AuthEnvironmentenum - expose the switch in debug builds only
Recommended env variable names:
SMBCLOUD_APP_ID_DEVSMBCLOUD_APP_SECRET_DEVSMBCLOUD_APP_ID_PRODUCTIONSMBCLOUD_APP_SECRET_PRODUCTION
Public-client security rule
Tauri, mobile, and browser apps are public clients. Treat app_id as public and app_secret as non-confidential if it is shipped in a client binary or browser bundle.
Implications:
- do not claim the client app secret is secure once distributed
- do not rely on embedded
app_secretas the main client authentication boundary - prefer backend-mediated flows, PKCE, or other public-client-safe patterns for stronger security
If the current SDK or API still requires app_secret from public clients, call out that limitation explicitly in code review or implementation notes.
macOS Tauri dev builds
tauri.conf.json minimumSystemVersion is not enough for tauri dev.
For apps that link Swift-based plugins such as tauri-plugin-iap, add src-tauri/.cargo/config.toml with:
MACOSX_DEPLOYMENT_TARGET=14.0-mmacosx-version-min=14.0for both Apple targets- host
CCandCXXoverrides to/usr/bin/clangand/usr/bin/clang++
If you see libswift_Concurrency.dylib at runtime, fix Cargo/macOS config first.
Web console conventions
The admin UI lives in smbcloud-web-console.
Use the Auth area, not generic settings pages, for tenant auth app management.
Expected behavior:
- scope auth view to selected workspace/project
- if workspace has an auth app, show the app and its users
- if not, allow:
- creating a new auth app
- attaching an existing tenant auth app
- show app id in list views
- hide app secret by default on detail views
- show linked/shared workspaces on detail pages
Typical change flow
- Decide whether the change is platform auth or tenant auth.
- Update Rails first.
- If OAuth providers are involved, confirm whether the provider is for
AuthUseror internalUser. Default tenant/customer providers toAuthUser. - Update Rust or WASM SDK endpoints/parsing if the API contract changed.
- Update Tauri or browser clients to match.
- Update the web console if auth app management changed.
- Validate end-to-end.
Validation
Use the smallest relevant checks.
Rails
bundle exec rails routes | grep 'v1/client\|auth_apps'ruby -con touched controller/model/mailer filesbundle exec rails db:migrateif schema changed
Rust SDK
cargo check -p smbcloud-auth-sdk(the core; also rebuilds the bindings as needed)cargo check -p smbcloud-auth-sdk-wasm
Tauri apps
cargo checkinsrc-tauripnpm buildin the app root when frontend changed
Web console
pnpm build
Browser SDK apps
pnpm build- verify login, logout, and session restore in the browser
- if environment override exists, verify both development and production modes
Common mistakes
- Sending tenant app credentials to
/v1/users - Using
OauthApplicationinstead ofAuthAppfor tenant login - Replacing platform client validation with tenant auth app validation
- Implementing Apple or Google for tenant users on platform
Userinstead ofAuthUser - Returning raw provider tokens as the primary tenant app session
- Treating a browser or native app
app_secretas confidential - Auto-confirming
AuthUserwhile telling the client to check email - Building smbCloud
AuthUserweb auth on top of unrelated NextAuth session state - Forgetting that
tauri devignorestauri.conf.jsonmacOS minimum version