Authentication

Authentication methods for the WordPress REST API

class wp_api.auth.BasicAuth(username, password)[source]

Bases: object

Basic Authentication for WordPress REST API

Note: This method is not recommended for production use unless over HTTPS

Parameters:
  • username (str)

  • password (str)

__init__(username, password)[source]

Initialize Basic Authentication

Parameters:
  • username (str) – WordPress username

  • password (str) – WordPress password

authenticate(session)[source]

Add authentication to session

Parameters:

session (requests.Session) – The session to authenticate

Return type:

None

class wp_api.auth.ApplicationPasswordAuth(username, app_password)[source]

Bases: object

Application Password Authentication for WordPress REST API

This is the recommended authentication method for WordPress 5.6+

Parameters:
  • username (str)

  • app_password (str)

__init__(username, app_password)[source]

Initialize Application Password Authentication

Parameters:
  • username (str) – WordPress username

  • app_password (str) – Application password generated in WordPress admin

authenticate(session)[source]

Add authentication to session

Parameters:

session (requests.Session) – The session to authenticate

Return type:

None

class wp_api.auth.OAuth1(consumer_key, consumer_secret, token=None, token_secret=None)[source]

Bases: object

OAuth1 Authentication for WordPress REST API

Parameters:
  • consumer_key (str)

  • consumer_secret (str)

  • token (str | None)

  • token_secret (str | None)

__init__(consumer_key, consumer_secret, token=None, token_secret=None)[source]

Initialize OAuth1 Authentication

Parameters:
  • consumer_key (str) – OAuth consumer key

  • consumer_secret (str) – OAuth consumer secret

  • token (str, optional) – OAuth token

  • token_secret (str, optional) – OAuth token secret

authenticate(session)[source]

Add authentication to session

Parameters:

session (requests.Session) – The session to authenticate

Return type:

None