mirror of
https://github.com/home-assistant/developers.home-assistant.git
synced 2025-07-19 07:16:29 +00:00
Explain LocalOAuth2ImplementationWithPkce in application credentials (#2584)
* Explain LocalOAuth2ImplementationWithPkce in application credentials * Adjusted imports in sample code * Remove URL anchor --------- Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
This commit is contained in:
parent
d3f358deb3
commit
abb16b8822
@ -74,6 +74,31 @@ async def async_get_auth_implementation(
|
||||
)
|
||||
```
|
||||
|
||||
### Authorization flow with PKCE Support
|
||||
|
||||
If you want to support [PKCE](https://www.rfc-editor.org/rfc/rfc7636) you can return the `LocalOAuth2ImplementationWithPkce` in `application_credentials.py` as follows:
|
||||
|
||||
```python
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.config_entry_oauth2_flow import AbstractOAuth2Implementation, LocalOAuth2ImplementationWithPkce
|
||||
from homeassistant.components.application_credentials import AuthImplementation, ClientCredential
|
||||
|
||||
|
||||
async def async_get_auth_implementation(
|
||||
hass: HomeAssistant, auth_domain: str, credential: ClientCredential
|
||||
) -> AbstractOAuth2Implementation:
|
||||
"""Return auth implementation for a custom auth implementation."""
|
||||
return LocalOAuth2ImplementationWithPkce(
|
||||
hass,
|
||||
auth_domain,
|
||||
credential.client_id,
|
||||
authorize_url="https://example.com/auth",
|
||||
token_url="https://example.com/oauth2/v4/token",
|
||||
client_secret=credential.client_secret, # optional `""` is default
|
||||
code_verifier_length=128 # optional
|
||||
)
|
||||
```
|
||||
|
||||
## Import YAML credentials
|
||||
|
||||
Credentials may be imported by integrations that used to accept YAML credentials using the import API `async_import_client_credential` provided by the application credentials integration.
|
||||
@ -149,4 +174,4 @@ async def async_get_description_placeholders(hass: HomeAssistant) -> dict[str, s
|
||||
}
|
||||
```
|
||||
|
||||
While developing locally, you will need to run `python3 -m script.translations develop` to see changes made to `strings.json` [More info on translating Home Assistant.](translations.md)
|
||||
While developing locally, you will need to run `python3 -m script.translations develop` to see changes made to `strings.json` [More info on translating Home Assistant.](translations.md)
|
||||
|
Loading…
x
Reference in New Issue
Block a user