Native applications are applications that have access to the operating system's native APIs and features. This means they can interact with the system in ways that are not possible with web applications. Examples of native applications include mobile applications, desktop applications, and even some types of web applications. They can access features of the operating system, especially for secure data storage.
A common (but deprecated) approach is to create a login page within the native app, allow users to enter their credentials, and then send them to the authentication server using the Resource Owner Password Credentials Grant flow. The native app then receives an access token from the authentication server and can use it to access the resource server.
This approach is currently deprecated because user secrets should only be known at the level of the authentication server. With the Resource Owner Password Credentials Grant:
Native applications should use the Authorization Code Flow with Proof Key for Code Exchange (PKCE) as specified in RFC 7636. This approach:
To securely handle authentication, a browser should be used so that login can be safely managed by the identity provider. The browser handles the front-channel part of the OAuth 2.0 flow and is responsible for obtaining the authorization code. The app itself can then exchange the code for a token, and the tokens can be safely stored in the app using the secure data storage capabilities of the platform.
Some platforms provide embedded browser components that can display web pages, often called WebViews. However, using WebViews for authentication is considered an anti-pattern because:
A better option is to use the system browser - the default browser of the operating system. This provides:
Every major mobile platform provides a special version of the system browser hardened for authentication use cases:
The Authorization Code flow works with a redirect URI that the authentication server uses to callback the application. Web apps live on a specific URL, but native apps don't have a traditional web address. So what do we use as the redirect URL?
The solution lies in the fact that URLs can be associated with an application in the OS. When specific URIs are called, the associated app can automatically be launched.
Example: When you click a Reddit link in your browser, the Reddit mobile app automatically opens (if installed).
Here's how it works for authentication:
app.test.com/callback)There are two primary approaches for registering redirect URIs with native applications:
Use a regular HTTPS URL that your organization controls:
https://app.test.com/callbackUse a custom scheme unique to your application:
com.test.app://callbackPKCE (Proof Key for Code Exchange) adds an additional layer of security to the Authorization Code flow, specifically designed to protect against authorization code interception attacks in native applications.
This ensures that even if an authorization code is intercepted, it cannot be exchanged for tokens without the original code verifier.
Proper token management is critical for maintaining security in native applications.
Use the secure data storage capabilities of the operating system to store tokens:
Implement proper refresh token rotation and revocation:
Reference: OAuth 2.0 Token Revocation (RFC 7009)
| Feature | Embedded WebView | System Browser |
|---|---|---|
| Security | ⚠️ Unsafe - Controlled by app | ✅ Hardened for authentication |
| Single Sign-On | ❌ Not available | ✅ Shared across apps |
| Browser Features | ❌ Limited or none | ✅ Fully featured |
| Password Managers | ❌ Not accessible | ✅ Available |
| User Trust | ⚠️ Lower - No visible domain | ✅ Higher - Visible address bar |
| OAuth 2.0 Compliance | ❌ Violates RFC 8252 | ✅ Follows best practices |
| MFA Support | ⚠️ Limited | ✅ Full support |
| Federation | ⚠️ Problematic | ✅ Seamless |
Explore these resources to implement secure authentication in native applications:
When implementing authentication for native applications: