For the complete documentation index, see llms.txt. Markdown versions of documentation pages are available by appending .md to the page URL.
Primary navigation
Overview Agent Access ChatGPT + Codex user docs Use cases

In your iOS or Android app

Add Sign in with ChatGPT to a mobile app with a direct app callback or a callback to your website backend.

Open Sign in with ChatGPT in the system browser using ASWebAuthenticationSession on iOS or Chrome Custom Tabs on Android. Use the system browser even if your app displays your website in a web view or the user has installed the ChatGPT app. Authorization servers can reject sign-in requests from embedded web views such as WKWebView on iOS or WebView on Android. The standard OAuth app review applies.

Choose where OpenAI sends the authorization code.

  • Directly to your app. The app receives the code through its registered HTTPS link. It can exchange the code on the device or send it to your backend for exchange.
  • Through your website backend. Your backend receives the code at your existing website callback, exchanges it, and redirects to the app with its own one-time code.

On iOS 17.4 and later, ASWebAuthenticationSession can receive an HTTPS callback. For a callback on app.example.com, add applinks:app.example.com and webcredentials:app.example.com to your app’s Associated Domains entitlement. In that host’s /.well-known/apple-app-site-association file, include the callback path under applinks and list your app identifier in the apps array under webcredentials.

Redirect directly to your app

Reuse your website’s public client ID for iOS and Android in the same environment. If your website client uses a secret, reuse the client through your website backend. If you don’t have a client yet, register one public client per environment for web, iOS, and Android.

Use a Universal Link on iOS or an App Link on Android. In OAuth apps, add each link’s exact HTTPS URL to the public client’s redirect URLs. If the dashboard asks you to verify a domain, use that domain or one of its subdomains for your callbacks. Public clients don’t use a client secret.

Use a fresh state, nonce, and PKCE verifier for each sign-in. Derive the S256 challenge from the verifier and send it with state and the nonce in the authorization request.

  • For a standalone app, generate and keep these values on the device. The app handles the callback and exchanges the code.
  • If your backend creates the app session, generate and keep these values on the backend. When the callback opens the app, send the code and returned state to the backend over HTTPS. Before exchanging the code, verify that the request comes from the app session that started sign-in, using a credential sent separately from the callback URL.

Match the returned state to the saved value. In the public-client token exchange example, use your app’s exact registered callback URL (for example, https://app.example.com/oauth/callback) as redirect_uri and the saved PKCE verifier as code_verifier. Verify the ID token and match its nonce to the saved nonce before creating a session.

For an on-device exchange, use an SDK that complies with OAuth 2.0 and OpenID Connect (OIDC). OpenAI currently has no dedicated iOS or Android SDK or sample for this flow.

Redirect through your website backend

From the mobile app, open your website sign-in route with your website’s existing client ID. The only redirect URL this flow needs in OAuth apps is your website’s HTTPS callback, for example https://example.com/oauth/callback. Pass that URL as redirect_uri. Your backend receives the OpenAI authorization code there, checks the returned state, exchanges the code using the PKCE verifier, and verifies the ID token. Keep any client secret on your backend.

To return to the app, have your backend issue its own short-lived, single-use code tied to the initiating app session. Send only that code through a separate HTTPS link on a domain associated with the app, such as https://app.example.com/return. Configure this return URL as a Universal Link on iOS or an App Link on Android. The app redeems the code with your backend over HTTPS.

On iOS 17.4 and later, configure the ASWebAuthenticationSession HTTPS callback to match only the final app link’s host (app.example.com) and path (/return). Matching the website callback can end the session before the app receives the backend’s one-time code.