Skip to content

Commit

Permalink
allow api endpoint '/api/v1/auth/tokens/register' to answer json requ…
Browse files Browse the repository at this point in the history
…ests with json response
  • Loading branch information
lekma committed Oct 30, 2024
1 parent d8b893e commit 75b49d4
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/invidious/routes/api/v1/authenticated.cr
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,8 @@ module Invidious::Routes::API::V1::Authenticated
user = env.get("user").as(User)
locale = env.get("preferences").as(Preferences).locale

case env.request.headers["Content-Type"]?
content_type = env.request.headers["Content-Type"]?
case content_type
when "application/x-www-form-urlencoded"
scopes = env.params.body.select { |k, _| k.match(/^scopes\[\d+\]$/) }.map { |_, v| v }
callback_url = env.params.body["callbackUrl"]?
Expand All @@ -419,7 +420,7 @@ module Invidious::Routes::API::V1::Authenticated
callback_url = URI.parse(callback_url)
end

if sid = env.get?("sid").try &.as(String)
if sid = env.get?("sid").try &.as(String) && content_type != "application/json"
env.response.content_type = "text/html"

csrf_token = generate_response(sid, {":authorize_token"}, HMAC_KEY, use_nonce: true)
Expand Down

0 comments on commit 75b49d4

Please sign in to comment.