public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
* [pve-devel] [PATCH v3 proxmox-openid-rs] fix Open ID with Azure as provider
@ 2022-04-01  9:44 Mira Limbeck
  2022-04-01 14:02 ` [pve-devel] applied: " Thomas Lamprecht
  0 siblings, 1 reply; 2+ messages in thread
From: Mira Limbeck @ 2022-04-01  9:44 UTC (permalink / raw)
  To: pve-devel

Azure doesn't accept `Transfer-Encoding: chunked` on their token endpoint,
but with the switch to ureq we always send requests with this set.

Fix by switching to `Content-Length` in the header instead. ureq only
sets `Transfer-Encoding: chunked` when the body length is not known
beforehand, which is the case when using `send`. See 
https://docs.rs/ureq/2.4.0/ureq/index.html#content-length-and-transfer-encoding

See https://forum.proxmox.com/threads/openid-401-with-azure-ad.105892/
for the issue.

Signed-off-by: Mira Limbeck <m.limbeck@proxmox.com>
---
v3:
 - fixed link in inline comment

v2:
 - added inline comment
 - removed the unnecessary `let bytes = ...` line
 - changed link in commit message to versioned docs.rs

probably also fixes https://bugzilla.proxmox.com/show_bug.cgi?id=3916,
but I could only reproduce this exact error message with Azure until
now.

 src/http_client.rs | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/src/http_client.rs b/src/http_client.rs
index a2bf6ee..e391421 100644
--- a/src/http_client.rs
+++ b/src/http_client.rs
@@ -75,7 +75,10 @@ pub fn http_client(request: HttpRequest) -> Result<HttpResponse, Error> {
     }
 
     let response = if let Method::POST = request.method {
-        req.send(&*request.body)
+        // send_bytes makes sure that Content-Length is set. This is important, because some
+        // endpoints don't accept `Transfer-Encoding: chunked`, which would otherwise be set.
+        // see https://docs.rs/ureq/2.4.0/ureq/index.html#content-length-and-transfer-encoding
+        req.send_bytes(request.body.as_slice())
     } else {
         req.call()
     }
-- 
2.30.2





^ permalink raw reply	[flat|nested] 2+ messages in thread

* [pve-devel] applied: [PATCH v3 proxmox-openid-rs] fix Open ID with Azure as provider
  2022-04-01  9:44 [pve-devel] [PATCH v3 proxmox-openid-rs] fix Open ID with Azure as provider Mira Limbeck
@ 2022-04-01 14:02 ` Thomas Lamprecht
  0 siblings, 0 replies; 2+ messages in thread
From: Thomas Lamprecht @ 2022-04-01 14:02 UTC (permalink / raw)
  To: Proxmox VE development discussion, Mira Limbeck

On 01.04.22 11:44, Mira Limbeck wrote:
> Azure doesn't accept `Transfer-Encoding: chunked` on their token endpoint,
> but with the switch to ureq we always send requests with this set.
> 
> Fix by switching to `Content-Length` in the header instead. ureq only
> sets `Transfer-Encoding: chunked` when the body length is not known
> beforehand, which is the case when using `send`. See 
> https://docs.rs/ureq/2.4.0/ureq/index.html#content-length-and-transfer-encoding
> 
> See https://forum.proxmox.com/threads/openid-401-with-azure-ad.105892/
> for the issue.
> 
> Signed-off-by: Mira Limbeck <m.limbeck@proxmox.com>
> ---
> v3:
>  - fixed link in inline comment
> 
> v2:
>  - added inline comment
>  - removed the unnecessary `let bytes = ...` line
>  - changed link in commit message to versioned docs.rs
> 
> probably also fixes https://bugzilla.proxmox.com/show_bug.cgi?id=3916,
> but I could only reproduce this exact error message with Azure until
> now.
> 
>  src/http_client.rs | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
>

great find!
applied, many thanks!




^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-04-01 14:02 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-01  9:44 [pve-devel] [PATCH v3 proxmox-openid-rs] fix Open ID with Azure as provider Mira Limbeck
2022-04-01 14:02 ` [pve-devel] applied: " Thomas Lamprecht

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal