Exchange OAuth authorization code for a WordPress JWT (GET)
GET/oauth/token
Browser-redirect flow: exchanges a provider authorization code for a WordPress session and redirects the browser to the WordPress admin (or login page on failure). The provider must be enabled in the plugin settings.
Supported providers: google, auth0, facebook, github.
Auth codes, IP allow-lists and the "Authentication enabled" setting do not apply to this endpoint; only the provider must be enabled.
Login start - provider only (no code, no error): the login buttons point
here. The plugin stores a random state in a 10-minute HttpOnly cookie
(sjl_oauth_state_<provider>) and answers 302 to the provider's consent screen
with that state.
Callback - the provider redirects back with code and state. The callback is
only accepted when state matches the cookie of the same browser (login CSRF
protection); the cookie is single use. Otherwise the code is not exchanged and the
browser is redirected to the login page with an error (error_code 129 in the audit
log). Links that send visitors straight to the provider, without the login start,
are rejected.
If the OAuth identity matches an existing WordPress user (by email), the user is logged in. If no match is found and "Register on OAuth login" is enabled, a new user is created automatically. On failure the browser is redirected to the WordPress login page.
Note: this endpoint is designed for browser redirect callbacks (OAuth consent screen redirect_uri). To obtain a JWT programmatically, use
POST /oauth/tokeninstead.
Request
Responses
- 200
- 302
- 403
- 422
The user has Two-Factor enabled: a small HTML page redirects the browser (meta
refresh + JavaScript) to the wp-login.php?action=validate_2fa form of the Two Factor
plugin. The session starts only after a valid code.
One of:
- Login start (
provideronly): redirect to the provider's consent screen withclient_id,redirect_uri,response_type=code,scopeandstate, plus aSet-Cookie: sjl_oauth_state_<provider>header. - Callback success: the user is logged in (created first when "Register on OAuth login" is on) and redirected to the WordPress admin.
- Callback failure (invalid
state, code rejected by the provider, or user not found): redirect towp-login.phpwith anerrorquery parameter.
Response Headers
https://accounts.google.com/o/oauth2/v2/auth?client_id=...&redirect_uri=...&response_type=code&scope=...&state=...The requested OAuth provider is not enabled in the plugin settings (error_code 70).
Unprocessable entity. One of:
provideris missing or unknown (error_code69).- The provider sent back an
errorwithout acode(for example, the user denied consent): the request has neithercodenor the token parameter (error_code71 Google, 77 Auth0, 97 Facebook, 101 GitHub).