Skip to content
Mobileadvanced

What is OAuth for native apps?

Updated Nov 30, 20263 min readBased on official documentation
What is OAuth for native apps?

In short

OAuth for native apps is a best practice where a mobile or desktop app sends its sign-in request through an external browser instead of a built-in web view. The user signs in on the browser, and the app receives the result through a redirect. This keeps passwords and cookies safer and lets users reuse existing sign-in sessions.

OAuth is a protocol that lets an app get limited access to a user's account on another service without handling the user's password. A native app is an app installed on a phone, tablet or computer, as opposed to a web app that runs only inside a browser. This page explains a best current practice for doing OAuth sign-in from native apps.

The core rule

The official guidance, published by the IETF as RFC 8252, says that OAuth authorization requests from native apps should go through an external user-agent. In practice that means the system browser. The app should not show its own embedded login form inside a web view. The RFC also calls this approach the "AppAuth pattern", after open-source libraries that implement it.

An external user-agent is a program that is separate from the app. The app cannot read its cookies, inspect its pages, or change its content. An embedded user-agent is a browser component hosted by the app itself. Because the app controls that component, it can see what the user types, which is the main reason the guidance rejects it.

How it works

The flow has a few steps. The app builds an authorization request URL and opens it in the system browser. The user signs in on the authorization server's own page, and may already be signed in from a previous app. The authorization server then sends the user back to the app with an authorization code, using a redirect URI. The app exchanges that code at the token endpoint for tokens.

The redirect back to the app can use one of three approaches described in the document. A private-use URI scheme is a custom scheme, such as a reverse domain name style address, registered with the operating system so that it opens the app. A claimed https URI is a web address that the app has proven it owns, and the operating system opens it in the app instead of the browser. A loopback interface redirect means the app starts a tiny local server on the device, usually on the loopback address, and the browser sends the response there.

The OAuth protocol itself does not change. The request and response are already defined as URLs, so this pattern works with standard OAuth 2.0 by changing how the URLs travel between the app and the browser.

Why it is safer

When the user signs in through the browser, the app never sees the password. The browser keeps the user's existing session, so single sign-on becomes possible. The user does not have to log in again for every new app, unless the authorization server policy requires it.

The RFC also points out that embedded web views allow the host app to copy credentials and cookies. Using the browser removes that risk. The authorization code should be protected as well. Because native apps are public clients that cannot keep a secret safely, the guidance recommends PKCE, a technique that binds the code to the app that requested it.

When to use it

Use this pattern whenever your native app needs to sign users in with an OAuth provider. This includes mobile apps, desktop apps and hybrid apps that run web technology inside a native shell. The RFC treats hybrid apps as native apps for this purpose.

The pattern also depends on the authorization server. The server must accept public clients and the redirect types you choose. Some server implementations assume every client is a confidential web server, so they may need changes. Check the server's support before you commit to a design.

Common mistakes

The most common mistake is using a web view for login because it looks simpler. This gives the app access to credentials and breaks single sign-on. Another mistake is choosing a redirect type the platform does not handle well, such as an unregistered custom scheme that another app could claim. Developers also sometimes forget that the app must handle the case where the user cancels the browser sign-in.

Another pitfall is treating the redirect as trusted without checks. Your app should validate the state parameter returned with the response, so that a response meant for a different request is rejected.

Alternatives

An embedded web view is the older approach the guidance discourages. An in-app browser tab, such as a platform browser component that shares the user's session, is a middle ground that the RFC describes as keeping the full security properties of the browser. If your platform offers it, it can give a smoother experience while staying close to the recommended model. For learning the basics of the protocol, start with the core OAuth 2.0 framework and then read the native app guidance.

FAQ

Can a native app still use a web view for OAuth login?

The guidance says no for OAuth authorization requests. A web view is hosted by the app, so the app can read credentials and cookies. Use the system browser or an in-app browser tab that keeps the browser's security properties.

What is the AppAuth pattern?

It is the name the RFC gives to this best practice, after open-source AppAuth libraries that implement it. The libraries help apps open the browser, handle redirects and exchange codes.

Do I need a client secret in a native app?

Native apps are public clients, so they cannot keep a secret safely. The guidance relies on other protections, such as PKCE, to secure the authorization code exchange.

Does this change the OAuth protocol?

No. The authorization request and response are already URLs, so the pattern works by changing how those URLs travel between the app and the browser.

Sources

This page is based on the official documentation below. Read it for full detail.

OAuth for native apps — official documentation ↗
blozhikDeveloper news from across the web, explained. Every story links to its original sources.