OAuth2 Resource Owner Password Credentials — Direct Credential Exchange
In this tutorial, you will learn about OAuth2 Resource Owner Password Credentials. We cover key concepts, practical examples, and best practices to help you master this topic.
The Resource Owner Password Credentials (ROPC) grant allows a client to exchange a user's username and password directly for an access token, bypassing the redirect-based authorization.
What You'll Learn
How ROPC works, its severe security limitations, why it is being deprecated, and suitable alternatives.
Why It Matters
ROPC is the most dangerous OAuth2 grant. It requires the client to handle passwords — the exact problem OAuth2 was designed to avoid. Understanding why it is dangerous helps you avoid and migrate away from it.
Real-World Use
ROPC was sometimes used for first-party mobile apps (the company owns both the app and the API). Most providers (Google, Microsoft, GitHub) have deprecated ROPC for new applications.
flowchart LR
A["User"] -->|"Username + Password"| B["Client App"]
B -->|"POST /token\ngrant_type=password"| C["Auth Server"]
C -->|"Access + Refresh Tokens"| B
B -->|"API call + Token"| D["Resource Server"]
style A fill:#dbeafe,stroke:#2563eb
style B fill:#fecaca,stroke:#dc2626
style C fill:#fef3c7,stroke:#d97706
style D fill:#dcfce7,stroke:#16a34a
Why ROPC Is Dangerous
| Risk | Description |
|---|---|
| Password exposure | The client app handles plain-text passwords |
| No granular consent | User cannot approve specific scopes |
| No MFA support | Password grant cannot handle MFA challenges |
| Credential storage | Client may store passwords for convenience |
| Deprecated | OAuth2 BCP recommends against it |
Common Mistakes
1. Using ROPC for Third-Party Apps
Third-party apps should never see user passwords. Use Authorization Code.
2. Not Handling MFA
ROPC fails when MFA is enabled. The error response does not indicate whether the password was correct.
3. Storing Passwords in Client
The client should discard the password immediately after token exchange.
4. Confusing ROPC with Client Credentials
ROPC uses user credentials. Client Credentials uses app credentials. Different purposes.
5. Believing ROPC Is Secure
Even with HTTPS, the password is exposed to the client application.
Practice Questions
- What grant collects usernames and passwords directly?
- Why is ROPC considered less secure than Authorization Code?
- What happens when MFA is enabled and a user uses ROPC?
- Is ROPC appropriate for third-party apps?
- What is the recommended alternative?
Answers:
- Resource Owner Password Credentials (grant_type=password).
- The client handles plain-text passwords. Authorization Code keeps passwords between user and auth server.
- The password grant fails because it cannot handle MFA challenges. Returns invalid_grant error.
- No. Third-party apps should never see user passwords.
- Authorization Code with PKCE provides the same UX without password exposure.
Challenge: Convert a password-grant flow to Authorization Code with PKCE. Explain the security improvements and UX differences.
FAQ
Mini Project
Write a script demonstrating why ROPC fails with MFA, then implement the same scenario using Authorization Code.
What's Next
Now learn about PKCE Extensions — the security extension for public OAuth2 clients.
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro