Native OAuth Callbacks on iOS and Android
Compare custom schemes, claimed HTTPS callbacks, state, PKCE, and embedded client secrets across mobile login lifecycles.
You’re reading a preview. Premium includes the full lesson and specialist practice. View the full curriculum.
A native callback crosses an operating-system boundary
A native OAuth login leaves the application, opens an external user agent, and later receives a callback through the operating system. Review all three places: how the application starts the login, how the platform routes the callback, and how the application exchanges the returned code.
A custom scheme such as com.example.hike:/oauth/callback identifies a handler through platform registration. Another installed application may be able to register a competing handler under some platform and deployment conditions. A claimed HTTPS callback uses a verified app-to-domain association, but the association and callback handling still need correct configuration.
Do not teach that every custom scheme is automatically compromised, or that one universal installation order decides the winner on every device. The threat model must specify a malicious co-installed application, the relevant operating-system behavior, and the authorization server's acceptance policy.
Compare state with proof of code possession
Select each step. Track the evidence available before the next operation.
Start. The legitimate app retains state; the original design creates no verifier.
pending.state = randomState()
openExternalBrowser(authorizeUrl)
Route. Under this fixture, the operating system delivers code and state to the second app.
callback: com.example.hike:/oauth/callback?code=C&state=S
Redeem. The second app can present the public client ID and intercepted code if the provider permits verifier-free exchange.
exchange(code=C, client_id=hike-native)
Repair. With PKCE enforced, the second app lacks the original verifier even though it saw state.
exchange(code=C, verifier=wrong) → reject
Review question: State and PKCE address different parts of the flow. Preserve state checks on every callback path and require the original verifier at code exchange.
State links a callback to a transaction the receiving client started. An attacker who sends an unsolicited callback should not be able to log the application into an unrelated account. PKCE binds redemption to the client instance that retained the verifier. These are related but distinct protections.
Legitimate app starts login:
state = S
verifier = V
challenge = SHA256(V)
Authorization server returns:
code = C
state = S
Competing app receives the callback:
it can see C and S
it does not learn V from that callback
If no PKCE challenge was recorded and the token endpoint accepts the public client ID plus code, the second app may redeem the intercepted code. The legitimate app's state check never runs because the callback went elsewhere. Adding state to that app does not fix this redemption path.
Conversely, a client can have PKCE yet mishandle callback transaction state or accept a response from an unexpected issuer. Use the complete library-supported flow and verify all relevant bindings rather than treating one parameter as a universal OAuth defense.