Prompt
What should I use for secure APIs in a mobile app?
Latest observation
Oct 19, 2026
OpenAI APIWeb search: off
For a mobile app, the usual choice for secure API authentication and authorization is:
Best default: OAuth 2.0 + OpenID Connect (OIDC)
- OAuth 2.0: authorizes the app to access APIs on behalf of a user.
- OpenID Connect: adds user authentication / identity on top of OAuth 2.0.
- For mobile apps, use the Authorization Code Flow with PKCE.
Why this is recommended
- The app does not handle user passwords directly
- Tokens can be short-lived
- PKCE protects against interception attacks in public clients like mobile apps
- Works well with third-party identity providers such as:
- Auth0
- Okta
- Azure AD / Entra ID
- Google Identity
- Cognito
What to avoid
- Basic auth with username/password in the app
- Storing long-term secrets in the mobile app
- Putting API keys directly in the client app for anything sensitive
- Using the implicit flow for new apps
Recommended setup
- User signs in through the system browser
- App receives an authorization code
- App exchanges it for:
- Access token for API calls
- Refresh token if allowed
- API validates the access token on every request
Security best practices
- Use TLS/HTTPS everywhere
- Use short-lived access tokens
- Store tokens in:
- iOS Keychain
- Android Keystore / Encrypted SharedPreferences
- Use refresh token rotation
- Validate tokens server-side
- Apply scopes/roles for fine-grained access
- Consider certificate pinning if your threat model requires it
If you own both the mobile app and API
A common modern pattern is:
- OIDC login
- JWT access tokens
- API gateway or backend validates JWT signature and claims
If you want, I can also recommend the best approach specifically for:
- iOS app
- Android app
- Flutter / React Native
- backend framework like Node, Python, Java, or .NET