CLI Managed Sessions¶
For simple programs and scripts, it is easiest for the program to defer
session management to the planet auth
CLI. This method will store session information in the user's home directory
in the ~/.planet.json file and ~/.planet/ directory. The Python SDK will
use the information saved in these locations to make API calls.
When this approach is taken, the authentication session will be shared between
actions taken by the planet utility and those taken by programs built
using the SDK. Changes made by one will impact the behavior of the other.
CLI managed sessions can be used for all authentication protocols supported by the SDK library.
Requirements and Limitations:
- The program must have read and write access to the user's home directory.
- This method requires that the end-user has access to and understands
the
planetCLI command needed to manage authentication. - This approach should not be used on public terminals or in cases where the user's home directory cannot be kept confidential.
Initialize Session - CLI Login¶
Session login can be performed using the following command. This command can
be used to initialize sessions using any of the supported authentication methods,
and will default to creating an OAuth2 user session.
Refer to the command's --help for more information.
planet auth login
A particular configuration may be selected by using the --auth-profile option.
planet-user is the default, but may be overridden
by the runtime environment.
planet auth login --auth-profile planet-user
planet auth login --auth-client-id <your-client-id> --auth-client-secret <your-client-secret>
planet auth login --auth-api-key <your-api-key>
Using Saved Session¶
Using a CLI managed session is the default behavior for SDK functions. Developing an application that uses a CLI managed session requires no additional action by the developer. When a developer chooses to create an application that behaves in this way, it will most often be done implicitly by relying on SDK default behavior, but it may also be done explicitly.
CLI Selected Session¶
The default behavior of the SDK is to defer which session is loaded to CLI.
Implicitly use CLI managed login sessions, deferring session selection to the user and the CLI. | |
|---|---|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | |
Explicitly use CLI managed login sessions, deferring session selection to the user and the CLI. | |
|---|---|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | |
Application Selected Session¶
Applications may be developed to always select a specific CLI managed profile. This may be useful in cases where an application wishes to guide the user experience towards expecting an auth session that is separate from the default sessions used by the CLI.
In cases where the application has access to the user's home directory and saved sessions, forcing the use of a particular profile circumvents the user's CLI managed preferences.
Note: This first example does not create the session my-app-profile.
This must be created either through a separate code path as show in
the Application Managed Sessions guide,
or by using a CLI command to copy an existing profile such as
planet auth profile copy planet-user my-app-profile.
Use a specific session that is shared with the CLI. | |
|---|---|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | |
It is also possible to force the use of the SDK's built-in OAuth2 application ID for interactive user applications. This capability is provided for developer convenience, primarily for smaller programs and scripts. Larger applications developed for multiple users should register a unique application ID.
This second example also initiates a login and does not save session state to storage. This means this example does not depend on the CLI, and may be considered a simple example of an Application Managed Session.
Use the Planet SDK with an OAuth2 user session initialized by the application and utilizing the SDK's built-in OAuth2 application ID. | |
|---|---|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | |