mirror of
https://github.com/home-assistant/developers.home-assistant.git
synced 2025-07-15 21:36:31 +00:00
Add more detailed application_credentials import instructions (#1331)
This commit is contained in:
parent
57cddc14bb
commit
0688f1e52f
@ -12,7 +12,16 @@ OAuth2 requires credentials that are shared between an application and provider.
|
|||||||
|
|
||||||
## Adding support
|
## Adding support
|
||||||
|
|
||||||
Integrations support application credentials with a file in the integration folder called `application_credentials.py` and implement the following:
|
Integrations support application credentials by adding a dependency on the `application_credentials` component in the `manifest.json`:
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
...
|
||||||
|
"dependencies": ["application_credentials"],
|
||||||
|
...
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Then add a file in the integration folder called `application_credentials.py` and implement the following:
|
||||||
|
|
||||||
```python
|
```python
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
@ -42,6 +51,44 @@ An `AuthorizationServer` represents the [OAuth2 Authorization server](https://da
|
|||||||
|
|
||||||
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.
|
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.
|
||||||
|
|
||||||
|
Here is an example from an integration that used to accept YAML credentials:
|
||||||
|
|
||||||
|
```python
|
||||||
|
from homeassistant.components.application_credentials import (
|
||||||
|
ClientCredential,
|
||||||
|
async_import_client_credential,
|
||||||
|
)
|
||||||
|
|
||||||
|
# Example configuration.yaml schema for an integration
|
||||||
|
CONFIG_SCHEMA = vol.Schema(
|
||||||
|
{
|
||||||
|
DOMAIN: vol.Schema(
|
||||||
|
{
|
||||||
|
vol.Required(CONF_CLIENT_ID): cv.string,
|
||||||
|
vol.Required(CONF_CLIENT_SECRET): cv.string,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||||
|
"""Set up the component."""
|
||||||
|
if DOMAIN not in config:
|
||||||
|
return True
|
||||||
|
|
||||||
|
await async_import_client_credential(
|
||||||
|
hass,
|
||||||
|
DOMAIN,
|
||||||
|
ClientCredential(
|
||||||
|
config[DOMAIN][CONF_CLIENT_ID],
|
||||||
|
config[DOMAIN][CONF_CLIENT_SECRET],
|
||||||
|
),
|
||||||
|
)
|
||||||
|
```
|
||||||
|
|
||||||
|
New integrations should not accept credentials in configuration.yaml as users
|
||||||
|
can instead enter credentials in the Application Credentials user interface.
|
||||||
|
|
||||||
### ClientCredential
|
### ClientCredential
|
||||||
|
|
||||||
A `ClientCredential` represents a client credential provided by the user.
|
A `ClientCredential` represents a client credential provided by the user.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user