Skip to content

Commit ffe796d

Browse files
ErigaraRoman Shanin
andauthored
fix(iceberg-catalog-rest): set application/x-www-form-urlencoded content-type header for oauth2 request (#1393)
## Which issue does this PR close? <!-- We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes #123` indicates that this PR will close issue #123. --> PR solves error when trying to authenticate through oauth2 endpoint. This issue appeared since `reqwest` changed it's behavior with this [PR](seanmonstar/reqwest#2527). ``` Error: Unexpected, context: { code: 400 Bad Request, operation: auth, url: http://127.0.0.1:8080/realms/iceberg/protocol/openid-connect/token, json: {"error":"invalid_request","error_description":"Missing form parameter: grant_type"} } => Received unexpected response, source: invalid type: string "invalid_request", expected struct ErrorModel at line 1 column 26 Caused by: invalid type: string "invalid_request", expected struct ErrorModel at line 1 column 26 ``` - Closes #. ## What changes are included in this PR? <!-- Provide a summary of the modifications in this PR. List the main changes such as new features, bug fixes, refactoring, or any other updates. --> - override `content-type` header to `application/x-www-form-urlencoded` for oauth2 authenticate requests ## Are these changes tested? yes: - tested it manually (through `keycloak`) - existing tests in repo <!-- Specify what test covers (unit test, integration test, etc.). If tests are not included in your PR, please explain why (for example, are they covered by existing tests)? --> Co-authored-by: Roman Shanin <rshanin@bhft.com>
1 parent 3ea6f47 commit ffe796d

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

crates/catalog/rest/src/client.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,12 +158,18 @@ impl HttpClient {
158158
.map(|(k, v)| (k.as_str(), v.as_str())),
159159
);
160160

161-
let auth_req = self
161+
let mut auth_req = self
162162
.request(Method::POST, &self.token_endpoint)
163163
.form(&params)
164164
.build()?;
165+
// extra headers add content-type application/json header it's necessary to override it with proper type
166+
// note that form call doesn't add content-type header if already present
167+
auth_req.headers_mut().insert(
168+
http::header::CONTENT_TYPE,
169+
http::HeaderValue::from_static("application/x-www-form-urlencoded"),
170+
);
165171
let auth_url = auth_req.url().clone();
166-
let auth_resp = self.execute(auth_req).await?;
172+
let auth_resp = self.client.execute(auth_req).await?;
167173

168174
let auth_res: TokenResponse = if auth_resp.status() == StatusCode::OK {
169175
let text = auth_resp

0 commit comments

Comments
 (0)