mirror of
https://github.com/iv-org/invidious.git
synced 2025-08-29 07:58:35 +00:00
New Token Scope
+ new scope for /ape/v1/ endpoints
This commit is contained in:
parent
a7b2aae296
commit
d5ebecb76a
@ -86,7 +86,12 @@ def validate_request(token, session, request, key, locale = nil)
|
|||||||
end
|
end
|
||||||
|
|
||||||
scopes = token["scopes"].as_a.map(&.as_s)
|
scopes = token["scopes"].as_a.map(&.as_s)
|
||||||
|
scope = ""
|
||||||
|
if scopes.includes?("::")
|
||||||
|
scope = "#{request.method}::#{request.path.lchop("/api/v1/").lstrip("/")}"
|
||||||
|
else
|
||||||
scope = "#{request.method}:#{request.path.lchop("/api/v1/auth/").lstrip("/")}"
|
scope = "#{request.method}:#{request.path.lchop("/api/v1/auth/").lstrip("/")}"
|
||||||
|
end
|
||||||
if !scopes_include_scope(scopes, scope)
|
if !scopes_include_scope(scopes, scope)
|
||||||
raise InfoException.new("Invalid scope")
|
raise InfoException.new("Invalid scope")
|
||||||
end
|
end
|
||||||
@ -107,11 +112,15 @@ def validate_request(token, session, request, key, locale = nil)
|
|||||||
end
|
end
|
||||||
|
|
||||||
def scope_includes_scope(scope, subset)
|
def scope_includes_scope(scope, subset)
|
||||||
|
if scope.includes?("::")
|
||||||
|
methods, endpoint = scope.split("::")
|
||||||
|
subset_methods, subset_endpoint = subset.split("::")
|
||||||
|
else
|
||||||
methods, endpoint = scope.split(":")
|
methods, endpoint = scope.split(":")
|
||||||
|
end
|
||||||
methods = methods.split(";").map(&.upcase).reject(&.empty?).sort!
|
methods = methods.split(";").map(&.upcase).reject(&.empty?).sort!
|
||||||
endpoint = endpoint.downcase
|
endpoint = endpoint.downcase
|
||||||
|
|
||||||
subset_methods, subset_endpoint = subset.split(":")
|
|
||||||
subset_methods = subset_methods.split(";").map(&.upcase).sort!
|
subset_methods = subset_methods.split(";").map(&.upcase).sort!
|
||||||
subset_endpoint = subset_endpoint.downcase
|
subset_endpoint = subset_endpoint.downcase
|
||||||
|
|
||||||
|
@ -73,7 +73,7 @@ module Invidious::Routes::API::V1::Authentication
|
|||||||
end
|
end
|
||||||
else
|
else
|
||||||
# send captcha
|
# send captcha
|
||||||
captcha = Invidious::User::Captcha.generate_text(HMAC_KEY, ":register")
|
captcha = Invidious::User::Captcha.generate_text(HMAC_KEY, "POST::register")
|
||||||
# Fix token formatting
|
# Fix token formatting
|
||||||
formatted_tokens : Array(JSON::Any) = Array(JSON::Any).new
|
formatted_tokens : Array(JSON::Any) = Array(JSON::Any).new
|
||||||
captcha["tokens"].each do |tok|
|
captcha["tokens"].each do |tok|
|
||||||
@ -280,3 +280,5 @@ struct CredentialsLogin
|
|||||||
property password : String
|
property password : String
|
||||||
property token : String
|
property token : String
|
||||||
end
|
end
|
||||||
|
|
||||||
|
text = "Ryan said, \"Hello!\""
|
||||||
|
Loading…
Reference in New Issue
Block a user