DaaS / Products / App User Auth with Database Backend

App User Auth with Database Backend

Build a web or mobile application using IDaaS for user authentication (SMS login, 2FA, social login) while storing user profiles and application data in RDS, requiring database account management for the application backend that integrates with the identity service.

Products involved

Scenario

Developers building customer-facing web or mobile apps need a secure, scalable identity layer without managing credentials directly. This workflow combines Alibaba Cloud IDaaS for multi-factor and social authentication with ApsaraDB RDS to persist user profiles, session metadata, and application data, requiring a dedicated backend service to bridge identity tokens with database operations.

Integration steps

  1. Configure IDaaS Authentication Methods: Enable SMS and TOTP via the IDaaS OpenAPI. Call POST /api/v1/apps/{AppId}/auth-methods with {"methods": ["sms", "totp"], "sms_sign_name": "YourApp", "totp_required": true}.
  2. Create RDS Application Account: Provision a dedicated service account using the RDS CLI: aliyun rds CreateAccount --DBInstanceId rm-uf6wjk5xxxx --AccountName app_backend --AccountPassword <secure_pwd> --AccountType Normal.
  3. Assign Database Privileges: Restrict access to the target schema: aliyun rds GrantAccountPrivilege --DBInstanceId rm-uf6wjk5xxxx --AccountName app_backend --DBName user_profiles --AccountPrivilege ReadWrite.
  4. Implement Backend Token Validation: IDaaS returns an OIDC JWT. Validate it server-side using the JWKS endpoint (/.well-known/jwks.json). Verify iss, exp, and aud claims before processing.
  5. Sync Identity to RDS: Extract the immutable sub claim and user attributes. Execute an upsert: INSERT INTO users (id, phone, email, last_login) VALUES ($1, $2, $3, NOW()) ON CONFLICT (id) DO UPDATE SET last_login = NOW();.
  6. Configure Webhook for Session Events: Register lifecycle hooks: POST /api/v1/apps/{AppId}/webhooks with {"events": ["user.login.success", "user.mfa.failed"], "url": "https://your-backend.com/idaas-events", "secret": "<hmac_key>"}.

Architecture

The frontend redirects users to IDaaS for authentication. Upon success, IDaaS issues a signed JWT to the client. The backend validates the token against IDaaS’s public keys, extracts the user identity, and uses the dedicated RDS service account to read/write profile data. RDS never handles authentication logic; it only stores application state mapped to the IDaaS sub claim. Webhooks sync identity lifecycle events to the database for audit and session tracking.

Prerequisites

Common pitfalls

Typical questions

FAQ

Q: How do I set up user authentication and database storage for a web or mobile application? A: You can build a web or mobile application by combining IDaaS for user authentication with ApsaraDB RDS for storing user profiles and application data. This integration requires configuring authentication methods like SMS login, 2FA, or social login through IDaaS, while managing database accounts and permissions via ApsaraDB RDS to support your application backend.