Oauth Callback

Summary

Classes

CallbackResult(auth_code, auth_error)

Holds the result of a single OAuth callback request.

Functions

build_authorize_url(app_id, redirect_uri, ...)

Build the OAuth2 authorization URL.

get_auth_code_via_server(authorize_url, ...)

Start a local HTTP server, open the browser for authorization, and wait for the callback.

Module Contents

class pyinaturalist.client.oauth_callback.CallbackResult(auth_code, auth_error) None

Bases: object

Holds the result of a single OAuth callback request.

auth_code = None
auth_error = None
pyinaturalist.client.oauth_callback.build_authorize_url(app_id, redirect_uri, code_challenge, state) str

Build the OAuth2 authorization URL.

Parameters:
  • app_id (str) – OAuth2 application ID (client ID).

  • redirect_uri (str) – The redirect URI registered with your iNaturalist application.

  • code_challenge (str | None) – PKCE code challenge (base64url-encoded SHA256 of the verifier).

  • state (str | None) – Optional random state value for CSRF protection.

Return type:

str

Returns:

The full authorization URL to open in the user’s browser.

pyinaturalist.client.oauth_callback.get_auth_code_via_server(authorize_url, port, timeout, state, open_url) CallbackResult

Start a local HTTP server, open the browser for authorization, and wait for the callback.

Parameters:
  • authorize_url (str) – The full authorization URL to open in the browser.

  • port (int) – Port for the local callback server.

  • timeout (int) – Seconds to wait for the callback.

  • state (str | None) – Expected state value for CSRF protection; None disables the check.

  • open_url (Callable[[str], None] | None) – Callback to open the authorization URL. Defaults to webbrowser.open.

Return type:

CallbackResult

Returns:

A CallbackResult with auth_code or auth_error set.

Raises:

.AuthenticationError – if the port is already in use.