mirror of
https://github.com/home-assistant/core.git
synced 2025-07-27 07:07:28 +00:00
Add OAuth 2.0 Bearer Token authentication to send_file for telegram_bot (#46567)
This commit is contained in:
parent
d4211c4a66
commit
fbf85fd86b
@ -26,6 +26,7 @@ from homeassistant.const import (
|
|||||||
CONF_API_KEY,
|
CONF_API_KEY,
|
||||||
CONF_PLATFORM,
|
CONF_PLATFORM,
|
||||||
CONF_URL,
|
CONF_URL,
|
||||||
|
HTTP_BEARER_AUTHENTICATION,
|
||||||
HTTP_DIGEST_AUTHENTICATION,
|
HTTP_DIGEST_AUTHENTICATION,
|
||||||
)
|
)
|
||||||
from homeassistant.exceptions import TemplateError
|
from homeassistant.exceptions import TemplateError
|
||||||
@ -255,7 +256,9 @@ def load_data(
|
|||||||
if url is not None:
|
if url is not None:
|
||||||
# Load data from URL
|
# Load data from URL
|
||||||
params = {"timeout": 15}
|
params = {"timeout": 15}
|
||||||
if username is not None and password is not None:
|
if authentication == HTTP_BEARER_AUTHENTICATION and password is not None:
|
||||||
|
params["headers"] = {"Authorization": f"Bearer {password}"}
|
||||||
|
elif username is not None and password is not None:
|
||||||
if authentication == HTTP_DIGEST_AUTHENTICATION:
|
if authentication == HTTP_DIGEST_AUTHENTICATION:
|
||||||
params["auth"] = HTTPDigestAuth(username, password)
|
params["auth"] = HTTPDigestAuth(username, password)
|
||||||
else:
|
else:
|
||||||
|
@ -29,9 +29,9 @@ send_message:
|
|||||||
selector:
|
selector:
|
||||||
select:
|
select:
|
||||||
options:
|
options:
|
||||||
- 'html'
|
- "html"
|
||||||
- 'markdown'
|
- "markdown"
|
||||||
- 'markdown2'
|
- "markdown2"
|
||||||
disable_notification:
|
disable_notification:
|
||||||
name: Disable notification
|
name: Disable notification
|
||||||
description: Sends the message silently. iOS users and Web users will not receive a notification, Android users will receive a notification with no sound.
|
description: Sends the message silently. iOS users and Web users will not receive a notification, Android users will receive a notification with no sound.
|
||||||
@ -65,7 +65,7 @@ send_message:
|
|||||||
object:
|
object:
|
||||||
message_tag:
|
message_tag:
|
||||||
name: Message tag
|
name: Message tag
|
||||||
description: 'Tag for sent message. In telegram_sent event data: {{trigger.event.data.message_tag}}'
|
description: "Tag for sent message. In telegram_sent event data: {{trigger.event.data.message_tag}}"
|
||||||
example: "msg_to_edit"
|
example: "msg_to_edit"
|
||||||
selector:
|
selector:
|
||||||
text:
|
text:
|
||||||
@ -94,16 +94,25 @@ send_photo:
|
|||||||
text:
|
text:
|
||||||
username:
|
username:
|
||||||
name: Username
|
name: Username
|
||||||
description: Username for a URL which require HTTP basic authentication.
|
description: Username for a URL which require HTTP authentication.
|
||||||
example: myuser
|
example: myuser
|
||||||
selector:
|
selector:
|
||||||
text:
|
text:
|
||||||
password:
|
password:
|
||||||
name: Password
|
name: Password
|
||||||
description: Password for a URL which require HTTP basic authentication.
|
description: Password (or bearer token) for a URL which require HTTP authentication.
|
||||||
example: myuser_pwd
|
example: myuser_pwd
|
||||||
selector:
|
selector:
|
||||||
text:
|
text:
|
||||||
|
authentication:
|
||||||
|
name: Authentication method
|
||||||
|
description: Define which authentication method to use. Set to `digest` to use HTTP digest authentication, or `bearer_token` for OAuth 2.0 bearer token authentication. Defaults to `basic`.
|
||||||
|
default: digest
|
||||||
|
selector:
|
||||||
|
select:
|
||||||
|
options:
|
||||||
|
- "digest"
|
||||||
|
- "bearer_token"
|
||||||
target:
|
target:
|
||||||
name: Target
|
name: Target
|
||||||
description: An array of pre-authorized chat_ids to send the document to. If not present, first allowed chat_id is the default.
|
description: An array of pre-authorized chat_ids to send the document to. If not present, first allowed chat_id is the default.
|
||||||
@ -116,9 +125,9 @@ send_photo:
|
|||||||
selector:
|
selector:
|
||||||
select:
|
select:
|
||||||
options:
|
options:
|
||||||
- 'html'
|
- "html"
|
||||||
- 'markdown'
|
- "markdown"
|
||||||
- 'markdown2'
|
- "markdown2"
|
||||||
disable_notification:
|
disable_notification:
|
||||||
name: Disable notification
|
name: Disable notification
|
||||||
description: Sends the message silently. iOS users and Web users will not receive a notification, Android users will receive a notification with no sound.
|
description: Sends the message silently. iOS users and Web users will not receive a notification, Android users will receive a notification with no sound.
|
||||||
@ -151,7 +160,7 @@ send_photo:
|
|||||||
object:
|
object:
|
||||||
message_tag:
|
message_tag:
|
||||||
name: Message tag
|
name: Message tag
|
||||||
description: 'Tag for sent message. In telegram_sent event data: {{trigger.event.data.message_tag}}'
|
description: "Tag for sent message. In telegram_sent event data: {{trigger.event.data.message_tag}}"
|
||||||
example: "msg_to_edit"
|
example: "msg_to_edit"
|
||||||
selector:
|
selector:
|
||||||
text:
|
text:
|
||||||
@ -174,16 +183,25 @@ send_sticker:
|
|||||||
text:
|
text:
|
||||||
username:
|
username:
|
||||||
name: Username
|
name: Username
|
||||||
description: Username for a URL which require HTTP basic authentication.
|
description: Username for a URL which require HTTP authentication.
|
||||||
example: myuser
|
example: myuser
|
||||||
selector:
|
selector:
|
||||||
text:
|
text:
|
||||||
password:
|
password:
|
||||||
name: Password
|
name: Password
|
||||||
description: Password for a URL which require HTTP basic authentication.
|
description: Password (or bearer token) for a URL which require HTTP authentication.
|
||||||
example: myuser_pwd
|
example: myuser_pwd
|
||||||
selector:
|
selector:
|
||||||
text:
|
text:
|
||||||
|
authentication:
|
||||||
|
name: Authentication method
|
||||||
|
description: Define which authentication method to use. Set to `digest` to use HTTP digest authentication, or `bearer_token` for OAuth 2.0 bearer token authentication. Defaults to `basic`.
|
||||||
|
default: digest
|
||||||
|
selector:
|
||||||
|
select:
|
||||||
|
options:
|
||||||
|
- "digest"
|
||||||
|
- "bearer_token"
|
||||||
target:
|
target:
|
||||||
name: Target
|
name: Target
|
||||||
description: An array of pre-authorized chat_ids to send the document to. If not present, first allowed chat_id is the default.
|
description: An array of pre-authorized chat_ids to send the document to. If not present, first allowed chat_id is the default.
|
||||||
@ -222,7 +240,7 @@ send_sticker:
|
|||||||
object:
|
object:
|
||||||
message_tag:
|
message_tag:
|
||||||
name: Message tag
|
name: Message tag
|
||||||
description: 'Tag for sent message. In telegram_sent event data: {{trigger.event.data.message_tag}}'
|
description: "Tag for sent message. In telegram_sent event data: {{trigger.event.data.message_tag}}"
|
||||||
example: "msg_to_edit"
|
example: "msg_to_edit"
|
||||||
selector:
|
selector:
|
||||||
text:
|
text:
|
||||||
@ -251,16 +269,25 @@ send_animation:
|
|||||||
text:
|
text:
|
||||||
username:
|
username:
|
||||||
name: Username
|
name: Username
|
||||||
description: Username for a URL which require HTTP basic authentication.
|
description: Username for a URL which require HTTP authentication.
|
||||||
example: myuser
|
example: myuser
|
||||||
selector:
|
selector:
|
||||||
text:
|
text:
|
||||||
password:
|
password:
|
||||||
name: Password
|
name: Password
|
||||||
description: Password for a URL which require HTTP basic authentication.
|
description: Password (or bearer token) for a URL which require HTTP authentication.
|
||||||
example: myuser_pwd
|
example: myuser_pwd
|
||||||
selector:
|
selector:
|
||||||
text:
|
text:
|
||||||
|
authentication:
|
||||||
|
name: Authentication method
|
||||||
|
description: Define which authentication method to use. Set to `digest` to use HTTP digest authentication, or `bearer_token` for OAuth 2.0 bearer token authentication. Defaults to `basic`.
|
||||||
|
default: digest
|
||||||
|
selector:
|
||||||
|
select:
|
||||||
|
options:
|
||||||
|
- "digest"
|
||||||
|
- "bearer_token"
|
||||||
target:
|
target:
|
||||||
name: Target
|
name: Target
|
||||||
description: An array of pre-authorized chat_ids to send the document to. If not present, first allowed chat_id is the default.
|
description: An array of pre-authorized chat_ids to send the document to. If not present, first allowed chat_id is the default.
|
||||||
@ -273,9 +300,9 @@ send_animation:
|
|||||||
selector:
|
selector:
|
||||||
select:
|
select:
|
||||||
options:
|
options:
|
||||||
- 'html'
|
- "html"
|
||||||
- 'markdown'
|
- "markdown"
|
||||||
- 'markdown2'
|
- "markdown2"
|
||||||
disable_notification:
|
disable_notification:
|
||||||
name: Disable notification
|
name: Disable notification
|
||||||
description: Sends the message silently. iOS users and Web users will not receive a notification, Android users will receive a notification with no sound.
|
description: Sends the message silently. iOS users and Web users will not receive a notification, Android users will receive a notification with no sound.
|
||||||
@ -331,16 +358,25 @@ send_video:
|
|||||||
text:
|
text:
|
||||||
username:
|
username:
|
||||||
name: Username
|
name: Username
|
||||||
description: Username for a URL which require HTTP basic authentication.
|
description: Username for a URL which require HTTP authentication.
|
||||||
example: myuser
|
example: myuser
|
||||||
selector:
|
selector:
|
||||||
text:
|
text:
|
||||||
password:
|
password:
|
||||||
name: Password
|
name: Password
|
||||||
description: Password for a URL which require HTTP basic authentication.
|
description: Password (or bearer token) for a URL which require HTTP authentication.
|
||||||
example: myuser_pwd
|
example: myuser_pwd
|
||||||
selector:
|
selector:
|
||||||
text:
|
text:
|
||||||
|
authentication:
|
||||||
|
name: Authentication method
|
||||||
|
description: Define which authentication method to use. Set to `digest` to use HTTP digest authentication, or `bearer_token` for OAuth 2.0 bearer token authentication. Defaults to `basic`.
|
||||||
|
default: digest
|
||||||
|
selector:
|
||||||
|
select:
|
||||||
|
options:
|
||||||
|
- "digest"
|
||||||
|
- "bearer_token"
|
||||||
target:
|
target:
|
||||||
name: Target
|
name: Target
|
||||||
description: An array of pre-authorized chat_ids to send the document to. If not present, first allowed chat_id is the default.
|
description: An array of pre-authorized chat_ids to send the document to. If not present, first allowed chat_id is the default.
|
||||||
@ -353,9 +389,9 @@ send_video:
|
|||||||
selector:
|
selector:
|
||||||
select:
|
select:
|
||||||
options:
|
options:
|
||||||
- 'html'
|
- "html"
|
||||||
- 'markdown'
|
- "markdown"
|
||||||
- 'markdown2'
|
- "markdown2"
|
||||||
disable_notification:
|
disable_notification:
|
||||||
name: Disable notification
|
name: Disable notification
|
||||||
description: Sends the message silently. iOS users and Web users will not receive a notification, Android users will receive a notification with no sound.
|
description: Sends the message silently. iOS users and Web users will not receive a notification, Android users will receive a notification with no sound.
|
||||||
@ -388,7 +424,7 @@ send_video:
|
|||||||
object:
|
object:
|
||||||
message_tag:
|
message_tag:
|
||||||
name: Message tag
|
name: Message tag
|
||||||
description: 'Tag for sent message. In telegram_sent event data: {{trigger.event.data.message_tag}}'
|
description: "Tag for sent message. In telegram_sent event data: {{trigger.event.data.message_tag}}"
|
||||||
example: "msg_to_edit"
|
example: "msg_to_edit"
|
||||||
selector:
|
selector:
|
||||||
text:
|
text:
|
||||||
@ -417,16 +453,25 @@ send_voice:
|
|||||||
text:
|
text:
|
||||||
username:
|
username:
|
||||||
name: Username
|
name: Username
|
||||||
description: Username for a URL which require HTTP basic authentication.
|
description: Username for a URL which require HTTP authentication.
|
||||||
example: myuser
|
example: myuser
|
||||||
selector:
|
selector:
|
||||||
text:
|
text:
|
||||||
password:
|
password:
|
||||||
name: Password
|
name: Password
|
||||||
description: Password for a URL which require HTTP basic authentication.
|
description: Password (or bearer token) for a URL which require HTTP authentication.
|
||||||
example: myuser_pwd
|
example: myuser_pwd
|
||||||
selector:
|
selector:
|
||||||
text:
|
text:
|
||||||
|
authentication:
|
||||||
|
name: Authentication method
|
||||||
|
description: Define which authentication method to use. Set to `digest` to use HTTP digest authentication, or `bearer_token` for OAuth 2.0 bearer token authentication. Defaults to `basic`.
|
||||||
|
default: digest
|
||||||
|
selector:
|
||||||
|
select:
|
||||||
|
options:
|
||||||
|
- "digest"
|
||||||
|
- "bearer_token"
|
||||||
target:
|
target:
|
||||||
name: Target
|
name: Target
|
||||||
description: An array of pre-authorized chat_ids to send the document to. If not present, first allowed chat_id is the default.
|
description: An array of pre-authorized chat_ids to send the document to. If not present, first allowed chat_id is the default.
|
||||||
@ -465,7 +510,7 @@ send_voice:
|
|||||||
object:
|
object:
|
||||||
message_tag:
|
message_tag:
|
||||||
name: Message tag
|
name: Message tag
|
||||||
description: 'Tag for sent message. In telegram_sent event data: {{trigger.event.data.message_tag}}'
|
description: "Tag for sent message. In telegram_sent event data: {{trigger.event.data.message_tag}}"
|
||||||
example: "msg_to_edit"
|
example: "msg_to_edit"
|
||||||
selector:
|
selector:
|
||||||
text:
|
text:
|
||||||
@ -494,16 +539,25 @@ send_document:
|
|||||||
text:
|
text:
|
||||||
username:
|
username:
|
||||||
name: Username
|
name: Username
|
||||||
description: Username for a URL which require HTTP basic authentication.
|
description: Username for a URL which require HTTP authentication.
|
||||||
example: myuser
|
example: myuser
|
||||||
selector:
|
selector:
|
||||||
text:
|
text:
|
||||||
password:
|
password:
|
||||||
name: Password
|
name: Password
|
||||||
description: Password for a URL which require HTTP basic authentication.
|
description: Password (or bearer token) for a URL which require HTTP authentication.
|
||||||
example: myuser_pwd
|
example: myuser_pwd
|
||||||
selector:
|
selector:
|
||||||
text:
|
text:
|
||||||
|
authentication:
|
||||||
|
name: Authentication method
|
||||||
|
description: Define which authentication method to use. Set to `digest` to use HTTP digest authentication, or `bearer_token` for OAuth 2.0 bearer token authentication. Defaults to `basic`.
|
||||||
|
default: digest
|
||||||
|
selector:
|
||||||
|
select:
|
||||||
|
options:
|
||||||
|
- "digest"
|
||||||
|
- "bearer_token"
|
||||||
target:
|
target:
|
||||||
name: Target
|
name: Target
|
||||||
description: An array of pre-authorized chat_ids to send the document to. If not present, first allowed chat_id is the default.
|
description: An array of pre-authorized chat_ids to send the document to. If not present, first allowed chat_id is the default.
|
||||||
@ -516,9 +570,9 @@ send_document:
|
|||||||
selector:
|
selector:
|
||||||
select:
|
select:
|
||||||
options:
|
options:
|
||||||
- 'html'
|
- "html"
|
||||||
- 'markdown'
|
- "markdown"
|
||||||
- 'markdown2'
|
- "markdown2"
|
||||||
disable_notification:
|
disable_notification:
|
||||||
name: Disable notification
|
name: Disable notification
|
||||||
description: Sends the message silently. iOS users and Web users will not receive a notification, Android users will receive a notification with no sound.
|
description: Sends the message silently. iOS users and Web users will not receive a notification, Android users will receive a notification with no sound.
|
||||||
@ -551,7 +605,7 @@ send_document:
|
|||||||
object:
|
object:
|
||||||
message_tag:
|
message_tag:
|
||||||
name: Message tag
|
name: Message tag
|
||||||
description: 'Tag for sent message. In telegram_sent event data: {{trigger.event.data.message_tag}}'
|
description: "Tag for sent message. In telegram_sent event data: {{trigger.event.data.message_tag}}"
|
||||||
example: "msg_to_edit"
|
example: "msg_to_edit"
|
||||||
selector:
|
selector:
|
||||||
text:
|
text:
|
||||||
@ -569,7 +623,7 @@ send_location:
|
|||||||
min: -90
|
min: -90
|
||||||
max: 90
|
max: 90
|
||||||
step: 0.001
|
step: 0.001
|
||||||
unit_of_measurement: '°'
|
unit_of_measurement: "°"
|
||||||
longitude:
|
longitude:
|
||||||
name: Longitude
|
name: Longitude
|
||||||
description: The longitude to send.
|
description: The longitude to send.
|
||||||
@ -579,7 +633,7 @@ send_location:
|
|||||||
min: -180
|
min: -180
|
||||||
max: 180
|
max: 180
|
||||||
step: 0.001
|
step: 0.001
|
||||||
unit_of_measurement: '°'
|
unit_of_measurement: "°"
|
||||||
target:
|
target:
|
||||||
name: Target
|
name: Target
|
||||||
description: An array of pre-authorized chat_ids to send the location to. If not present, first allowed chat_id is the default.
|
description: An array of pre-authorized chat_ids to send the location to. If not present, first allowed chat_id is the default.
|
||||||
@ -613,7 +667,7 @@ send_location:
|
|||||||
object:
|
object:
|
||||||
message_tag:
|
message_tag:
|
||||||
name: Message tag
|
name: Message tag
|
||||||
description: 'Tag for sent message. In telegram_sent event data: {{trigger.event.data.message_tag}}'
|
description: "Tag for sent message. In telegram_sent event data: {{trigger.event.data.message_tag}}"
|
||||||
example: "msg_to_edit"
|
example: "msg_to_edit"
|
||||||
selector:
|
selector:
|
||||||
text:
|
text:
|
||||||
@ -654,9 +708,9 @@ edit_message:
|
|||||||
selector:
|
selector:
|
||||||
select:
|
select:
|
||||||
options:
|
options:
|
||||||
- 'html'
|
- "html"
|
||||||
- 'markdown'
|
- "markdown"
|
||||||
- 'markdown2'
|
- "markdown2"
|
||||||
disable_web_page_preview:
|
disable_web_page_preview:
|
||||||
name: Disable web page preview
|
name: Disable web page preview
|
||||||
description: Disables link previews for links in the message.
|
description: Disables link previews for links in the message.
|
||||||
|
@ -637,6 +637,7 @@ HTTP_BAD_GATEWAY: Final = 502
|
|||||||
HTTP_SERVICE_UNAVAILABLE: Final = 503
|
HTTP_SERVICE_UNAVAILABLE: Final = 503
|
||||||
|
|
||||||
HTTP_BASIC_AUTHENTICATION: Final = "basic"
|
HTTP_BASIC_AUTHENTICATION: Final = "basic"
|
||||||
|
HTTP_BEARER_AUTHENTICATION: Final = "bearer_token"
|
||||||
HTTP_DIGEST_AUTHENTICATION: Final = "digest"
|
HTTP_DIGEST_AUTHENTICATION: Final = "digest"
|
||||||
|
|
||||||
HTTP_HEADER_X_REQUESTED_WITH: Final = "X-Requested-With"
|
HTTP_HEADER_X_REQUESTED_WITH: Final = "X-Requested-With"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user