Skip to content

Commit 6c97fd4

Browse files
doc improvements (#21)
* Prefer "paramters" over "args" for function documentation. * working on improving the docs * change stats badge * split up the API docs into two pages. * fix broken link to readthedocs * link checkers for docs * reorder secetions * link to multiple sources of download stats * adjust nav * improve CLI example * small fixes
1 parent 01824ee commit 6c97fd4

File tree

50 files changed

+463
-339
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+463
-339
lines changed

.github/workflows/release-build.yml

+3
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ jobs:
5757
# - name: "Nox: MKDocs Build"
5858
# run: |
5959
# nox -s mkdocs_build
60+
# - name: "Nox: MKDocs Check Links"
61+
# run: |
62+
# nox -s mkdocs_checklinks
6063
# - name: "Save Artifacts - MkDocs"
6164
# uses: actions/upload-artifact@v4
6265
# with:

.github/workflows/test.yml

+5
Original file line numberDiff line numberDiff line change
@@ -173,3 +173,8 @@ jobs:
173173
- name: 'Nox: MKDocs Build'
174174
run: |
175175
nox -s mkdocs_build
176+
# Not checking the links in the pipeline right now.
177+
# This is throwing some false positives on intra-md links
178+
# that build OK, and would also be caught by our mkdocs
179+
# strict mode setting.
180+
# nox -s mkdocs_checklinks

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# Planet Auth Utility Library
22
[![Build Status](https://github.com/planetlabs/planet-auth-python/actions/workflows/test.yml/badge.svg)](https://github.com/planetlabs/planet-auth-python/actions/workflows/test.yml)
3-
[![PyPI Downloads](https://static.pepy.tech/badge/planet-auth)](https://pepy.tech/projects/planet-auth)
43
[![Read The Docs](https://app.readthedocs.org/projects/planet-auth/badge/)](https://planet-auth.readthedocs.io/)
4+
[![PyPI Downloads (pypistats.org)](https://img.shields.io/pypi/dm/planet-auth)](https://pypistats.org/packages/planet-auth)
5+
[![PyPI Downloads (peppy.tech)](https://static.pepy.tech/badge/planet-auth)](https://pepy.tech/projects/planet-auth)
56

67
The Planet Auth Library provides generic authentication utilities for clients
78
and for services. For clients, it provides means to obtain access tokens that

docs/api-planet-auth-utils.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# ::: planet_auth_utils
2+
options:
3+
show_root_full_path: true
4+
inherited_members: true
5+
show_submodules: true
6+
show_if_no_docstring: false

docs/api-planet-auth.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# ::: planet_auth
2+
options:
3+
show_root_full_path: true
4+
inherited_members: true
5+
show_submodules: true
6+
show_if_no_docstring: false

docs/api.md

-15
This file was deleted.

docs/built-ins.md

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Built-in Auth Client Profile Injection
2+
3+
TODO: Document how applications may inject built-in auth client profiles for
4+
a smoother application user and developer experience.

docs/changelog.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# Changelog
22

3-
## 2.1.0 - 2025 TBD
3+
## 2.1.0 - 2025-??-??
44
- Initial public release targeting integration with the
55
[Planet Client for Python](https://github.com/planetlabs/planet-client-python).
66

7-
## [Unreleased: 2.0.*] - YYYY-MM-DD
7+
## [Unreleased: 2.0.*]
88
- All releases in the 2.0.X series are development releases, even if not
99
tagged as such. This work included some shakedowns of the release pipelines.

docs/configuration.md

+25-35
Original file line numberDiff line numberDiff line change
@@ -9,40 +9,13 @@ AuthClient Configuration dictionaries may either be provided directly, or loaded
99
from disk when saved in a `Profile` (See below).
1010

1111
While it is possible to work directly with the lower level implementation
12-
classes, it is generally simpler to use the higher level management code in
13-
[planet_auth.Auth][], or the factory methods in [planet_auth.AuthClient][]
14-
and [planet_auth.AuthClientConfig][] to configure and instantiate instances.
15-
Directly using the lower level implementations should not be necessary in
16-
most cases.
12+
classes, it is generally simpler to organize the working set of objects
13+
with an [Auth Context][planet_auth.Auth] instance created from one of the
14+
factory methods in [planet_auth_utils.PlanetAuthFactory][]
1715

1816
A number of auth client implementations are provided. Clients should
1917
select the one most appropriate for their use case.
2018

21-
### Planet Legacy Client
22-
Implemented by [planet_auth.PlanetLegacyAuthClient][] and [planet_auth.PlanetLegacyAuthClientConfig][]
23-
24-
Configuration:
25-
```json linenums="1" title="~/.planet/_profile_name_/auth_client.json"
26-
{% include 'auth-client-config/planet-legacy.json' %}
27-
```
28-
29-
Profile Usage:
30-
```python linenums="1"
31-
from planet_auth import Auth
32-
33-
auth_ctx = Auth.initialize_from_profile(profile="_profile_name_")
34-
```
35-
36-
37-
Direct Usage:
38-
```python linenums="1"
39-
from planet_auth import Auth
40-
auth_ctx = Auth.initialize_from_config_dict(
41-
client_config={ ... content of auth_client.json ... },
42-
token_file="/my_token_file.json"
43-
)
44-
```
45-
4619
### OAuth Clients
4720
#### Auth Code with PKCE
4821
Implemented by [planet_auth.AuthCodeAuthClient][] and [planet_auth.AuthCodeClientConfig][]
@@ -54,18 +27,16 @@ Configuration:
5427

5528
Profile Usage:
5629
```python linenums="1"
30+
{% include 'snippets/auth-client-context-from-saved-profile.py' %}
31+
5732
from planet_auth import Auth
5833

5934
auth_ctx = Auth.initialize_from_profile(profile="_profile_name_")
6035
```
6136

6237
Direct Usage:
6338
```python linenums="1"
64-
from planet_auth import Auth
65-
auth_ctx = Auth.initialize_from_config_dict(
66-
client_config={ ... content of auth_client.json ... },
67-
token_file="/my_token_file.json"
68-
)
39+
{% include 'snippets/auth-client-context-oauth-direct.py' %}
6940
```
7041

7142
#### Auth Code with PKCE and Client Public Key
@@ -164,6 +135,25 @@ outbound calls, which is one of the primary aims of most auth client types.
164135
Instead, this client configuration can only be used to validate incoming
165136
tokens.
166137

138+
### Planet Legacy Client
139+
Implemented by [planet_auth.PlanetLegacyAuthClient][] and [planet_auth.PlanetLegacyAuthClientConfig][]
140+
141+
Configuration:
142+
```json linenums="1" title="~/.planet/_profile_name_/auth_client.json"
143+
{% include 'auth-client-config/planet-legacy.json' %}
144+
```
145+
146+
Profile Usage:
147+
```python linenums="1"
148+
{% include 'snippets/auth-client-context-from-saved-profile.py' %}
149+
```
150+
151+
152+
Direct Usage:
153+
```python linenums="1"
154+
{% include 'snippets/auth-client-context-pl-legacy-direct.py' %}
155+
```
156+
167157
## Environment Variables
168158
See [planet_auth_utils.EnvironmentVariables][] for a list of environment variables.
169159

docs/examples-cli.md

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# CLI Examples
2+
3+
## Embedding the `plauth` Command in Another `click` Program
4+
It is possible to embed the [`plauth`](./cli-plauth.md) command into other programs to
5+
present a unified experience that leverages the _Planet Auth Library_
6+
package for client authentication plumbing. This is done by using
7+
a special version of the command that is configured for embedding.
8+
9+
When using the embedded version of the command, the outer application
10+
must take on the responsibility of instantiating the auth context and
11+
handling command line options so that this context may be available
12+
to click commands that are outside the `plauth` root command.
13+
14+
```python linenums="1"
15+
{% include 'cli/embed-plauth-click.py' %}
16+
```
17+
18+
## Advanced Embedding
19+
Beyond simple embedding, it is possible for an application to customize some
20+
the appearance and behavior of the command.
21+
22+
For example, an application may rename commands or hide options and sub-commands
23+
it does not wish to expose to the user. For an extensive example of this in a
24+
downstream application, you can look at the
25+
[Planet SDK](https://github.com/planetlabs/planet-client-python)'s
26+
CLI program, which both embeds the whole `plauth` command as a hidden
27+
root level sub-command [`planet plauth`](https://github.com/planetlabs/planet-client-python/blob/main/planet/cli/cli.py),
28+
and cherry-picks specific sub-commands to power its own
29+
[`auth`](https://github.com/planetlabs/planet-client-python/blob/main/planet/cli/auth.py)
30+
sub-command. This allows the downstream application to leverage the _Planet Auth Library_,
31+
while also using [configuration injection](./built-ins.md) to provide a smoother end-user experience

docs/examples-client.md

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# Client Examples
2+
Client examples cover scenarios in which a program wishes to use
3+
the planet auth utilities as a client, obtaining credentials
4+
from authentication services so that they may be used to
5+
make authenticated requests to other network services.
6+
7+
## OAuth Client Authentication
8+
A custom auth client profile may be used to configure the AuthClient
9+
to use an arbitrary OAuth2 auth service to obtain access tokens for
10+
use with application APIs.
11+
See [Configuration and Profiles](./configuration.md) for more information
12+
on client types and profiles.
13+
14+
1. Create a `~/.planet/<profile_name>/auth_client.json` or `~/.planet/<profile_name>/auth_client.sops.json` file.
15+
For example, to create a custom profile named "my-custom-profile", create the following:
16+
```json linenums="1" title="~/.planet/my-custom-profile/auth_client.json"
17+
{% include 'auth-client-config/oauth-auth-code-grant-public-client.json' %}
18+
```
19+
2. Initialize the client library with the specified profile. Note: if the environment variable
20+
`PL_AUTH_PROFILE` is set, it will be detected automatically by [planet_auth_utils.PlanetAuthFactory][],
21+
and it will not be necessary to explicitly pass in the profile name:
22+
```python linenums="1"
23+
{% include 'auth-client/oauth/initialize-client-lib-on-disk-profile.py' %}
24+
```
25+
An alternative to creating a file on disk is to initialize_from_profile a client
26+
purely in memory. For some runtime environments where local storage may
27+
not be available or trusted, this may be more appropriate:
28+
```python linenums="1"
29+
{% include 'auth-client/oauth/initialize-client-lib-in-memory.py' %}
30+
```
31+
3. Perform initial login to obtain and save long term credentials, if required
32+
by the configured profile. An initial login is usually required for auth
33+
clients that act on behalf of a user and need to perform an interactive login.
34+
Clients configured for service operation may frequently skip this step:
35+
```python linenums="1"
36+
{% include 'auth-client/oauth/perform-oauth-initial-login.py' %}
37+
```
38+
4. Make authenticated requests:
39+
* Option 1 - Using `requests`:
40+
```python linenums="1"
41+
{% include 'auth-client/oauth/make-oauth-authenticated-requests-request.py' %}
42+
```
43+
* Option 2 - Using `httpx`:
44+
```python linenums="1"
45+
{% include 'auth-client/oauth/make-oauth-authenticated-httpx-request.py' %}
46+
```
47+
48+
## Performing a Device Login
49+
The procedure for performing initial user login on a UI limited device
50+
is slightly different. Rather than simply calling `login()`, it is necessary
51+
to initiate the process with a call to `device_login_initiate()`, display the
52+
returned information to the user so that the user may authorize the client
53+
asynchronously, and complete the process by calling `device_login_complete()`.
54+
This procedure only applies to clients that are permitted to use the
55+
Device Authorization OAuth flow.
56+
57+
```python linenums="1"
58+
{% include 'auth-client/oauth/perform-oauth-device-login.py' %}
59+
```
60+
61+
## Planet Legacy Authentication
62+
The proprietary Planet legacy authentication protocol is targeted for future
63+
deprecation. It should not be used for any new development.
64+
65+
### Initial Login
66+
```python linenums="1"
67+
{% include 'auth-client/planet-legacy/perform-legacy-initial-login.py' %}
68+
```
69+
70+
### Authenticated `requests` Call
71+
```python linenums="1"
72+
{% include 'auth-client/planet-legacy/make-legacy-authenticated-requests-request.py' %}
73+
```

docs/examples-installation.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Installation
2+
3+
## Install from _PyPI.org_ using `pip`
4+
Install the required modules:
5+
```shell
6+
pip install planet-auth
7+
```

docs/examples-service.md

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Service Examples
2+
Service examples cover scenarios in which a program wishes to use
3+
the planet auth utilities as a service, verifying the authenticity
4+
of access credentials presented to the service by a client.
5+
6+
It should be noted that Services may also act as clients when making
7+
calls to other services. When a service is acting in such a capacity,
8+
the [Client Examples](./examples-client.md) apply.
9+
When the service is acting on behalf of itself, it is likely that
10+
a [OAuth2 Client Credentials](./configuration.md#client-credentials-with-client-secret)
11+
configuration applies.
12+
13+
When a service is acting on behalf of one of its clients...
14+
(TODO: cover this.)
15+
16+
## Verifying OAuth Clients
17+
The [planet_auth.OidcMultiIssuerValidator][] class is provided to assist with
18+
common OAuth client authentication scenarios. This class can be configured
19+
with a single authority for normal operations, and may optionally be configured
20+
with a secondary authorities. This allows for complex deployments such as
21+
the seamless migration between auth servers over time.
22+
23+
This utility class may be configured for entirely local token validation,
24+
or may be configured to check token validity against the OAuth token inspection
25+
endpoint. For most operations, local validation is expected to be used, as
26+
it is more performant, not needing to make blocking network calls, and more
27+
robust, not depending on external service availability. For high value operations,
28+
remote validation may be performed which checks whether the specific access
29+
token has been revoked.
30+
31+
Tokens are normally not long-lived. Token lifespans should be selected to
32+
strike a balance between security concerns and allow frequent use of local
33+
validation, and not overburden the token inspection endpoint.
34+
35+
Checking tokens against the OAuth token inspection endpoint does require the
36+
use of OAuth clients that are authorized to use the endpoint, and may not
37+
be available to anonymous clients, depending on the auth server configuration.
38+
39+
### Local Access Token Validation
40+
```python linenums="1" title="Basic usage of OidcMultiIssuerValidator. Validate access tokens locally."
41+
{% include 'service/flask--oidc-multi-issuer--local-only-validation.py' %}
42+
```
43+
44+
### Local and Remote Access Token Validation
45+
```python linenums="1" title="Advanced usage of OidcMultiIssuerValidator. Validate access tokens against OAuth inspection endpoints using custom auth clients."
46+
{% include 'service/flask--oidc-multi-issuer--local-and-remote-validation.py' %}
47+
```
48+
49+
## Verifying Planet Legacy Client
50+
This is not supported by this library.

0 commit comments

Comments
 (0)