Namespaces | |
| indieauth | |
| login_flow | |
| mfa_setup_flow | |
Classes | |
| class | LinkUserView |
| class | RevokeTokenView |
| class | TokenView |
Variables | |
| CONFIG_SCHEMA = cv.empty_config_schema(DOMAIN) | |
| int | DELETE_CURRENT_TOKEN_DELAY = 2 |
| string | DOMAIN = "auth" |
| RetrieveResultType | |
| StoreResultType | |
Component to allow users to login and get tokens.
# POST /auth/token
This is an OAuth2 endpoint for granting tokens. We currently support the grant
types "authorization_code" and "refresh_token". Because we follow the OAuth2
spec, data should be send in formatted as x-www-form-urlencoded. Examples will
be in JSON as it's more readable.
## Grant type authorization_code
Exchange the authorization code retrieved from the login flow for tokens.
{
"client_id": "https://hassbian.local:8123/",
"grant_type": "authorization_code",
"code": "411ee2f916e648d691e937ae9344681e"
}
Return value will be the access and refresh tokens. The access token will have
a limited expiration. New access tokens can be requested using the refresh
token. The value ha_auth_provider will contain the auth provider type that was
used to authorize the refresh token.
{
"access_token": "ABCDEFGH",
"expires_in": 1800,
"refresh_token": "IJKLMNOPQRST",
"token_type": "Bearer",
"ha_auth_provider": "homeassistant"
}
## Grant type refresh_token
Request a new access token using a refresh token.
{
"client_id": "https://hassbian.local:8123/",
"grant_type": "refresh_token",
"refresh_token": "IJKLMNOPQRST"
}
Return value will be a new access token. The access token will have
a limited expiration.
{
"access_token": "ABCDEFGH",
"expires_in": 1800,
"token_type": "Bearer"
}
## Revoking a refresh token
It is also possible to revoke a refresh token and all access tokens that have
ever been granted by that refresh token. Response code will ALWAYS be 200.
{
"token": "IJKLMNOPQRST",
"action": "revoke"
}
# Websocket API
## Get current user
Send websocket command `auth/current_user` will return current user of the
active websocket connection.
{
"id": 10,
"type": "auth/current_user",
}
The result payload likes
{
"id": 10,
"type": "result",
"success": true,
"result": {
"id": "USER_ID",
"name": "John Doe",
"is_owner": true,
"credentials": [{
"auth_provider_type": "homeassistant",
"auth_provider_id": null
}],
"mfa_modules": [{
"id": "totp",
"name": "TOTP",
"enabled": true
}]
}
}
## Create a long-lived access token
Send websocket command `auth/long_lived_access_token` will create
a long-lived access token for current user. Access token will not be saved in
Home Assistant. User need to record the token in secure place.
{
"id": 11,
"type": "auth/long_lived_access_token",
"client_name": "GPS Logger",
"lifespan": 365
}
Result will be a long-lived access token:
{
"id": 11,
"type": "result",
"success": true,
"result": "ABCDEFGH"
}
# POST /auth/external/callback
This is an endpoint for OAuth2 Authorization callbacks used by integrations
that link accounts with other cloud providers using LocalOAuth2Implementation
as part of a config flow.
|
private |
Create an in memory store.
Definition at line 446 of file __init__.py.
| bool homeassistant.components.auth.async_setup | ( | HomeAssistant | hass, |
| ConfigType | config | ||
| ) |
Component to allow users to login.
Definition at line 184 of file __init__.py.
| str homeassistant.components.auth.create_auth_code | ( | HomeAssistant | hass, |
| str | client_id, | ||
| Credentials | credential | ||
| ) |
Create an authorization code to fetch tokens.
Definition at line 177 of file __init__.py.
| None homeassistant.components.auth.websocket_create_long_lived_access_token | ( | HomeAssistant | hass, |
| websocket_api.ActiveConnection | connection, | ||
| dict[str, Any] | msg | ||
| ) |
Create or a long-lived access token.
Definition at line 533 of file __init__.py.
| None homeassistant.components.auth.websocket_current_user | ( | HomeAssistant | hass, |
| websocket_api.ActiveConnection | connection, | ||
| dict[str, Any] | msg | ||
| ) |
Return the current user.
Definition at line 488 of file __init__.py.
| None homeassistant.components.auth.websocket_delete_all_refresh_tokens | ( | HomeAssistant | hass, |
| websocket_api.ActiveConnection | connection, | ||
| dict[str, Any] | msg | ||
| ) |
Handle delete all refresh tokens request.
Definition at line 625 of file __init__.py.
| None homeassistant.components.auth.websocket_delete_refresh_token | ( | HomeAssistant | hass, |
| websocket_api.ActiveConnection | connection, | ||
| dict[str, Any] | msg | ||
| ) |
Handle a delete refresh token request.
Definition at line 601 of file __init__.py.
| None homeassistant.components.auth.websocket_refresh_token_set_expiry | ( | HomeAssistant | hass, |
| websocket_api.ActiveConnection | connection, | ||
| dict[str, Any] | msg | ||
| ) |
Handle a set expiry of a refresh token request.
Definition at line 723 of file __init__.py.
| None homeassistant.components.auth.websocket_refresh_tokens | ( | HomeAssistant | hass, |
| websocket_api.ActiveConnection | connection, | ||
| dict[str, Any] | msg | ||
| ) |
Return metadata of users refresh tokens.
Definition at line 557 of file __init__.py.
| None homeassistant.components.auth.websocket_sign_path | ( | HomeAssistant | hass, |
| websocket_api.ActiveConnection | connection, | ||
| dict[str, Any] | msg | ||
| ) |
Handle a sign path request.
Definition at line 696 of file __init__.py.
| homeassistant.components.auth.CONFIG_SCHEMA = cv.empty_config_schema(DOMAIN) |
Definition at line 171 of file __init__.py.
| int homeassistant.components.auth.DELETE_CURRENT_TOKEN_DELAY = 2 |
Definition at line 173 of file __init__.py.
| string homeassistant.components.auth.DOMAIN = "auth" |
Definition at line 166 of file __init__.py.
| homeassistant.components.auth.RetrieveResultType |
Definition at line 169 of file __init__.py.
| homeassistant.components.auth.StoreResultType |
Definition at line 168 of file __init__.py.