Skip to content
Merged
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions docs/core/platform/application_credentials.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
---
title: "Application Credentials"
---

Integrations support [Configuration via OAuth2](https://developers.home-assistant.io/docs/config_entries_config_flow_handler#configuration-via-oauth2) and the preferred approach is to use the Home Assistant Cloud Account Linking service. Integrations may also allow users to provide their own OAuth client credentials by adding a `application_credentials.py` and implementing the right functions.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The first sentence is missing something. Now it sounds like all integrations support oauth2.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also here, we should clarify the sentence about cloud account linking, as implementing a local implementation isn't optional.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apologies, I deleted the wrong thing, i'll get back to this after sleeping on it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, i revamped this to add more of the bigger picture overview. I also updated the config flow docs to point here, then added a link back here with details on cloud account linking and nabu casa. Really, I think the cloud account linking stuff may deserve its own page. Or we could move more of that detail here, with a dedicated section, even though it does not technically involve this platform it may be the natural place to show the progression.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, a separate page about account linking may be needed. Although it's not so much for the contributor to do. It's mostly Nabu Casa that needs to set up an application. For now this is good, I think.

Comment thread
frenck marked this conversation as resolved.
Outdated

:::note
Application Credentials is under active development and integrations should still prefer using `LocalOAuth2Implementation`.
:::

## Adding support

Integrations support application credentials with a file in the integration folder called `application_credentials.py` and implement the following:

```python
from homeassistant.core import HomeAssistant
from homeassistant.components.application_credentials import AuthorizationServer


async def async_get_authorization_server(
self, hass: HomeAssistant
) -> AuthorizationServer:
"""Return authorization server."""
return AuthorizationServer(
authorize_url="https://example.com/auth",
token_url="https://example.com/oauth2/v4/token"
)
```

See below for details on backwards compatibility with YAML credentials.

## AuthorizationServer
Comment thread
allenporter marked this conversation as resolved.
Outdated

An `AuthorizationServer` represents the [OAuth2 Authorization server](https://datatracker.ietf.org/doc/html/rfc6749) used for an integration.

| Name | Type | | Description |
| ------------- | ---- | -------------------------------------------------------------------------------------------------- | ----------- |
| authorize_url | str | **Required** | The OAuth authorize URL that the user is redirected to during the configuration flow. |
| token_url | str | **Required** | The URL used for obtaining an access token. |

## Import YAML credentials

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😍


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.

The `auth_domain` is the domain for the auth implementation in the config entry, which is typically the domain specified in an existing `LocalOAuth2Implementation`.

## ClientCredential

A `ClientCredential` represents a client credential provided by the user.

| Name | Type | | Description |
| ------------- | ---- | ------------------------------------------------------------------------- | ----------- |
| client_id | str | **Required** | The OAuth Client ID provided by the user. |
| client_secret | str | **Required** | The OAuth Client Secret provided by the user. |