Skip to content
Open
Changes from all 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
25 changes: 15 additions & 10 deletions lib/omniauth/strategies/telegram.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ class Telegram
option :bot_name, nil
option :bot_secret, nil
option :button_config, {}
option :version, '22'

REQUIRED_FIELDS = %w[id hash]
HASH_FIELDS = %w[auth_date first_name id last_name photo_url username]
REQUIRED_FIELDS = %w[id hash].freeze
HASH_FIELDS = %w[auth_date first_name id last_name photo_url username].freeze

def request_phase
html = <<-HTML
Expand All @@ -28,10 +29,10 @@ def request_phase
<body>
HTML

data_attrs = options.button_config.map { |k,v| "data-#{k}=\"#{v}\"" }.join(" ")
data_attrs = options.button_config.map { |k, v| "data-#{k}=\"#{v}\"" }.join(" ")

html << "<script async
src=\"https://telegram.org/js/telegram-widget.js?4\"
src=\"https://telegram.org/js/telegram-widget.js?#{options.version}\"
data-telegram-login=\"#{options.bot_name}\"
data-auth-url=\"#{callback_url}\"
#{data_attrs}></script>"
Expand All @@ -58,17 +59,17 @@ def callback_phase

info do
{
name: "#{request.params["first_name"]} #{request.params["last_name"]}",
nickname: request.params["username"],
first_name: request.params["first_name"],
last_name: request.params["last_name"],
image: request.params["photo_url"]
name: full_name(request.params["first_name"], request.params["last_name"]),
nickname: request.params["username"],
first_name: request.params["first_name"],
last_name: request.params["last_name"],
image: request.params["photo_url"]
}
end

extra do
{
auth_date: Time.at(request.params["auth_date"].to_i)
auth_date: Time.at(request.params["auth_date"].to_i)
}
end

Expand All @@ -80,6 +81,10 @@ def check_errors
return :session_expired unless check_session
end

def full_name(first_name, last_name)
[first_name, last_name].compact.join(' ')
end

def check_required_fields
REQUIRED_FIELDS.all? { |f| request.params.include?(f) }
end
Expand Down