mirror of
https://github.com/iv-org/invidious.git
synced 2025-05-22 08:01:20 -04:00
Add 'sign_token'
This commit is contained in:
parent
5dc45c35e6
commit
aad0f90a9d
2 changed files with 43 additions and 0 deletions
|
@ -211,6 +211,25 @@ def create_response(user_id, operation, key, db, expire = 6.hours)
|
|||
return challenge, token
|
||||
end
|
||||
|
||||
def sign_token(key, hash)
|
||||
string_to_sign = [] of String
|
||||
hash.each do |key, value|
|
||||
if key == "signature"
|
||||
next
|
||||
end
|
||||
|
||||
case value
|
||||
when Array
|
||||
string_to_sign << "#{key}=#{value.sort.join(",")}"
|
||||
else
|
||||
string_to_sign << "#{key}=#{value}"
|
||||
end
|
||||
end
|
||||
|
||||
string_to_sign = string_to_sign.sort.join("\n")
|
||||
return Base64.encode(OpenSSL::HMAC.digest(:sha256, key, string_to_sign)).strip
|
||||
end
|
||||
|
||||
def validate_response(challenge, token, user_id, operation, key, db, locale)
|
||||
if !challenge
|
||||
raise translate(locale, "Hidden field \"challenge\" is a required field")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue