Skip to content

Commit 78bb57d

Browse files
committed
FEATURE: add option to encode request as json
1 parent 2ec8f90 commit 78bb57d

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

‎config/settings.yml

+6
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ login:
77
oauth2_authorize_url: ""
88
oauth2_authorize_signup_url: ""
99
oauth2_token_url: ""
10+
oauth2_token_request_encoding:
11+
default: "form_encoded"
12+
type: enum
13+
choices:
14+
- form_encoded
15+
- json
1016
oauth2_token_url_method:
1117
default: "POST"
1218
type: enum

‎plugin.rb

+4-2
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,10 @@ def register_middleware(omniauth)
121121
opts[:client_options][:auth_scheme] = :request_body
122122
opts[:token_params] = {
123123
headers: {
124-
"Authorization" => basic_auth_header,
124+
"Authorization" => basic_auth_header
125125
},
126126
}
127+
opts[:token_params][:headers]["Content-Type"] = "application/json" if SiteSetting.oauth2_token_request_encoding == "json"
127128
elsif SiteSetting.oauth2_send_auth_header?
128129
opts[:client_options][:auth_scheme] = :basic_auth
129130
else
@@ -141,7 +142,8 @@ def register_middleware(omniauth)
141142
{ bodies: true, formatter: OAuth2FaradayFormatter }
142143
end
143144

144-
builder.request :url_encoded # form-encode POST params
145+
encoding = SiteSetting.oauth2_token_request_encoding == "form_encoded" ? :url_encoded : :json
146+
builder.request encoding
145147
builder.adapter FinalDestination::FaradayAdapter # make requests with FinalDestination::HTTP
146148
end
147149
}

0 commit comments

Comments
 (0)