Auth¶
Summary¶
Classes
Functions
|
Get an access token using the user's iNaturalist username and password, using the Resource Owner Password Credentials Flow. |
Attempt to get iNaturalist credentials from the system keyring |
|
|
Store iNaturalist credentials in the system keyring for future use. |
|
Determine if an access token is valid |
Module Contents¶
- pyinaturalist.auth.get_access_token(username=None, password=None, app_id=None, app_secret=None, jwt=True, refresh=False)¶
Get an access token using the user’s iNaturalist username and password, using the Resource Owner Password Credentials Flow. Requires registering an iNaturalist app.
Notes
API reference: https://www.inaturalist.org/pages/api+reference#auth
See Authentication for additional options for storing credentials.
This can be used to get either a JWT or OAuth token. These can be used interchangeably for many endpoints. JWT is preferred for newer endpoints.
Examples
With direct keyword arguments:
>>> from pyinaturalist import get_access_token >>> access_token = get_access_token( >>> username='my_inaturalist_username', >>> password='my_inaturalist_password', >>> app_id='33f27dc63bdf27f4ca6cd95dd9dcd5df', >>> app_secret='bbce628be722bfe2abd5fc566ba83de4', >>> )
With environment variables or keyring configured:
>>> access_token = get_access_token()
If you would like to run custom requests for endpoints not yet implemented in pyinaturalist, you can authenticate these requests by putting the token in your HTTP headers as follows:
>>> import requests >>> requests.get( >>> 'https://www.inaturalist.org/observations/1234', >>> headers={'Authorization': f'Bearer {access_token}'}, >>> )
- Parameters:
username (
Optional
[str
]) – iNaturalist username (same as the one you use to login on inaturalist.org)password (
Optional
[str
]) – iNaturalist password (same as the one you use to login on inaturalist.org)jwt (
bool
) – Return a JSON Web Token; otherwise return an OAuth2 access token.refresh (
bool
) – Do not use any cached tokens, even if they are not expired
- Raises:
if credentials are invalid
- Return type:
- pyinaturalist.auth.get_keyring_credentials()¶
Attempt to get iNaturalist credentials from the system keyring
- pyinaturalist.auth.set_keyring_credentials(username, password, app_id, app_secret)¶
Store iNaturalist credentials in the system keyring for future use.