FEATURE: add option to encode request as json

This commit is contained in:
Jean Perez 2023-07-26 12:08:59 -03:00
parent 2ec8f90bb3
commit 78bb57daf1
2 changed files with 10 additions and 2 deletions

View File

@ -7,6 +7,12 @@ login:
oauth2_authorize_url: "" oauth2_authorize_url: ""
oauth2_authorize_signup_url: "" oauth2_authorize_signup_url: ""
oauth2_token_url: "" oauth2_token_url: ""
oauth2_token_request_encoding:
default: "form_encoded"
type: enum
choices:
- form_encoded
- json
oauth2_token_url_method: oauth2_token_url_method:
default: "POST" default: "POST"
type: enum type: enum

View File

@ -121,9 +121,10 @@ class ::OAuth2BasicAuthenticator < Auth::ManagedAuthenticator
opts[:client_options][:auth_scheme] = :request_body opts[:client_options][:auth_scheme] = :request_body
opts[:token_params] = { opts[:token_params] = {
headers: { headers: {
"Authorization" => basic_auth_header, "Authorization" => basic_auth_header
}, },
} }
opts[:token_params][:headers]["Content-Type"] = "application/json" if SiteSetting.oauth2_token_request_encoding == "json"
elsif SiteSetting.oauth2_send_auth_header? elsif SiteSetting.oauth2_send_auth_header?
opts[:client_options][:auth_scheme] = :basic_auth opts[:client_options][:auth_scheme] = :basic_auth
else else
@ -141,7 +142,8 @@ class ::OAuth2BasicAuthenticator < Auth::ManagedAuthenticator
{ bodies: true, formatter: OAuth2FaradayFormatter } { bodies: true, formatter: OAuth2FaradayFormatter }
end end
builder.request :url_encoded # form-encode POST params encoding = SiteSetting.oauth2_token_request_encoding == "form_encoded" ? :url_encoded : :json
builder.request encoding
builder.adapter FinalDestination::FaradayAdapter # make requests with FinalDestination::HTTP builder.adapter FinalDestination::FaradayAdapter # make requests with FinalDestination::HTTP
end end
} }