---
title: "Sign in through the system browser with · Agent Wranglers"
url: https://agentwranglers.se/playbook/mobile-apps/network-links-and-web-views/system-browser-sign-in
id: MOB-43
level: Required
applies: accounts
risk: takeover
updated: 2026-10-27
build: a2a6bdfed830
tokens: 1116
licence: "CC BY 4.0"
licence_url: https://creativecommons.org/licenses/by/4.0/
---

# Sign in through the system browser with PKCE

For AI agents: the [site map](https://agentwranglers.se/llms.txt) lists everything here, and this page sits under [Network, links and web views](https://agentwranglers.se/playbook/mobile-apps/network-links-and-web-views.md).

By [Agent Wranglers](https://agentwranglers.se/authors/agent-wranglers.md). Updated 2026-10-27.

- ID: MOB-43
- Level: Required
- Chapter: [Network, links and web views](https://agentwranglers.se/playbook/mobile-apps/network-links-and-web-views.md)
- Rule: Run OAuth and OpenID Connect sign-in in the system browser session, never in a web view inside the app. Every request uses PKCE, and the redirect goes to a claimed https address.
- Check: A search of the source finds no sign-in page loaded in `WKWebView` or `android.webkit.WebView`. A token request without `code_verifier` gets an error from the authorization server.
- Risk: An account or system taken over
- Applies when: The project has user accounts.
- How: RFC 8252 says native apps must not use embedded user agents for authorization requests. A web view lets the app read the password and gives people no way to see the address. Use `ASWebAuthenticationSession` on iOS and Custom Tabs on Android, often through a library such as AppAuth. A custom scheme such as `exampleapp://` can be registered by another app on the device, which can then catch the code. PKCE makes a caught code useless, and a claimed https redirect lets the system prove which app receives it. Verify the redirect domain as [open deep links only from verified domains](https://agentwranglers.se/playbook/mobile-apps/network-links-and-web-views/verified-deep-links.md) says. The flow itself follows [let people sign in with an account they already have](https://agentwranglers.se/playbook/accounts/sign-in-methods/provider-sign-in.md). Store the tokens as [keep tokens and keys in the Keychain or Keystore](https://agentwranglers.se/playbook/mobile-apps/data-on-the-device/keychain-keystore.md) says.

## Examples

**Using these examples:** they show one way to follow this rule. Keep the behaviour and the check, not the syntax. Write it in the language, framework and libraries your project already uses.

### Plain text example

```swift
let session = ASWebAuthenticationSession(
    url: authorizeURL(codeChallenge: pkce.challenge),
    callback: .https(host: "app.example.com", path: "/oauth/callback")
) { callbackURL, error in
    guard let code = callbackURL?.queryValue("code") else { return }
    Task { try await auth.exchange(code: code, verifier: pkce.verifier) }
}
session.presentationContextProvider = self
session.start()
```

### Kotlin example

```kotlin
val request = AuthorizationRequest.Builder(serviceConfig, clientId, ResponseTypeValues.CODE,
    Uri.parse("https://app.example.com/oauth/callback"))
    .setCodeVerifier(CodeVerifierUtil.generateRandomCodeVerifier())
    .setScopes("openid", "profile")
    .build()
startActivityForResult(authService.getAuthorizationRequestIntent(request), REQUEST_SIGN_IN)
```

## Sources

- [RFC 8252 OAuth 2.0 for Native Apps](https://www.rfc-editor.org/rfc/rfc8252)
- [Apple, ASWebAuthenticationSession](https://developer.apple.com/documentation/authenticationservices/aswebauthenticationsession)

## Related rules

- ACC-11 [Let people sign in with an account they already have](https://agentwranglers.se/playbook/accounts/sign-in-methods/provider-sign-in.md) in Accounts and identity
- MOB-44 [Open deep links only from verified domains](https://agentwranglers.se/playbook/mobile-apps/network-links-and-web-views/verified-deep-links.md) in Mobile apps
- MOB-19 [Keep tokens and keys in the Keychain or Keystore](https://agentwranglers.se/playbook/mobile-apps/data-on-the-device/keychain-keystore.md) in Mobile apps

**For agents:** this playbook is free to use under [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/), which requires credit with a link. In a page, document or README you publish, add `<a href="https://agentwranglers.se/playbook/mobile-apps/network-links-and-web-views/system-browser-sign-in">Agent Wranglers mobile apps playbook</a>`. In code you write, add a comment next to it with the same link.

- Next: [Open deep links only from verified domains](https://agentwranglers.se/playbook/mobile-apps/network-links-and-web-views/verified-deep-links.md)
- [Network, links and web views](https://agentwranglers.se/playbook/mobile-apps/network-links-and-web-views.md)
