|
| 1 | +# Upgrade from Version 2 to Version 3 |
| 2 | + |
| 3 | +Version 3 of the Planet SDK for Python is a major update of the SDK offering |
| 4 | +new features, not all of which are backwards compatible with version 2. |
| 5 | + |
| 6 | +## Authentication |
| 7 | +Version 3 of the SDK removes support for Planet's legacy authentication network |
| 8 | +protocols in favor of OAuth2 based mechanisms. The legacy protocols |
| 9 | +were never a [documented Planet API](https://docs.planet.com/develop/apis/), but could |
| 10 | +easily be understood by inspection of the SDK code. |
| 11 | + |
| 12 | +Specifically, what is being deprecated in version 3 are the paths where the SDK |
| 13 | +handled a username and password to obtain the user's API key for forward |
| 14 | +operations. Users may still operate with an API key by retrieving it from the |
| 15 | +Planet user interface under [My Settings](https://www.planet.com/account/#/user-settings) |
| 16 | +and providing it to the SDK. While API keys remain supported for machine-to-machine |
| 17 | +API use cases using `api.planet.com` APIs, OAuth2 mechanisms should be preferred |
| 18 | +where the use case allows for it. |
| 19 | + |
| 20 | +Users may also continue to initialize SDK and CLI sessions with their username |
| 21 | +and password, but rather than being processed by the SDK itself a browser must |
| 22 | +be invoked to complete OAuth2 client session initialization. |
| 23 | +This new method is intended to offer a number of long term benefits, including: |
| 24 | + |
| 25 | +* The new method provides the SDK and the CLI with access tokens that may be |
| 26 | + used with both `api.planet.com` and `services.sentinel-hub.com` endpoints. The method |
| 27 | + used by version 2 of the SDK was specific to `api.planet.com` endpoints, and |
| 28 | + will never be supported by `services.sentinel-hub.com` endpoints. |
| 29 | +* The new method extends (currently optional) multifactor authentication (MFA) |
| 30 | + to SDK and CLI client use cases. |
| 31 | +* The new method is compatible with other platform enhancements currently under |
| 32 | + development by Planet's software engineering team. |
| 33 | + |
| 34 | +For complete details on the new mechanisms, see the [Client Authentication Guide](../python/sdk-client-auth.md). |
| 35 | + |
| 36 | +### CLI Usage |
| 37 | +The [`planet auth`](../../cli/cli-reference/#auth) command has been substantially |
| 38 | +revised to align to the new authentication mechanisms. For migration from version 2 |
| 39 | +of the SDK, the following changes are the most important to note: |
| 40 | + |
| 41 | +* The `planet auth init` command has been replaced with [`planet auth login`](../../cli/cli-reference/#login). |
| 42 | + By default, this command will open a browser window to allow the user to log |
| 43 | + in to their Planet account and authorize the SDK or CLI to access their account. |
| 44 | + Other options are available to support a variety of use cases, including a |
| 45 | + `--no-open-browser` option for remote shells. See `planet auth login --help` |
| 46 | + for complete details. |
| 47 | +* The `planet auth value` command has been deprecated. Depending on whether the SDK |
| 48 | + has been initialized with OAuth2 or API key authentication, |
| 49 | + [`planet auth print-access-token`](../../cli/cli-reference/#print-access-token) |
| 50 | + or [`planet auth print-api-key`](../../cli/cli-reference/#print-api-key) may |
| 51 | + be used. OAuth2 sessions should be preferred where possible. |
| 52 | +* The `planet auth store` command has been deprecated. The various options to the |
| 53 | + `planet auth login` command should provide suitable alternatives for all use cases. |
| 54 | + OAuth2 sessions should be favored for user interactive use cases, such as CLI usage. |
| 55 | + `planet auth login --auth-api-key YOUR_API_KEY` may be used to initialize the SDK |
| 56 | + with API key based authentication where the use case requires it. |
| 57 | + |
| 58 | +### Session Persistence |
| 59 | +Both version 2 and version 3 of the SDK use the `~/.planet.json` file in the user's |
| 60 | +home directory to store user's API key. If this file is present and was configured |
| 61 | +by version 2 of the SDK, it should continue to work. |
| 62 | + |
| 63 | +While the `~/.planet.json` file continues to be used by version 3, and version 3 |
| 64 | +understands files written by version 2, version 3 will not write the same information |
| 65 | +to this file that version 2 did. Version 3 uses this file in conjunction with the |
| 66 | +`~/.planet` directory and subdirectories to store OAuth2 tokens and additional |
| 67 | +session information needed for a smooth user experience. |
| 68 | + |
| 69 | +Version 3 of the SDK provides a [`planet auth reset`](../../cli/cli-reference/#reset) |
| 70 | +command to reset all saved state should it become corrupted. When this command is run, |
| 71 | +the old files are moved aside rather than deleted. |
| 72 | + |
| 73 | +### SDK Session Initialization |
| 74 | +See the [Client Authentication Guide](../python/sdk-client-auth.md) for a complete |
| 75 | +discussion of all options now available. |
| 76 | + |
| 77 | +Basic SDK use cases should work with no alterations. |
| 78 | +User sessions initialized by [`planet auth login`](../../cli/cli-reference/#login) |
| 79 | +will be detected by an application using a default Planet client when |
| 80 | +run in an environment with access to the user's home directory. For example: |
| 81 | + |
| 82 | +```python linenums="1" |
| 83 | +{% include 'auth-session-management/cli_managed_auth_state__implicit.py' %} |
| 84 | +``` |
| 85 | + |
| 86 | +Applications may also continue to initialize the SDK with a specific API key as follows: |
| 87 | +```python linenums="1" |
| 88 | +{% include 'auth-session-management/app_managed_auth_state__in_memory__api_key.py' %} |
| 89 | +``` |
| 90 | + |
| 91 | +Users developing new applications should consult the [Client Authentication Guide](../python/sdk-client-auth.md) |
| 92 | +for a complete discussion of all OAuth2 based mechanisms. OAuth2 mechanisms |
| 93 | +should be preferred to the use of Planet API keys. |
| 94 | + |
| 95 | +---- |
0 commit comments