Blame SOURCES/0022-oidc_child-use-client-secret-if-available-to-get-dev.patch

0034f4
From 3e296c70d56e2aa83ce882d2ac1738f85606fd7a Mon Sep 17 00:00:00 2001
0034f4
From: Sumit Bose <sbose@redhat.com>
0034f4
Date: Thu, 18 Aug 2022 14:01:34 +0200
0034f4
Subject: [PATCH 22/24] oidc_child: use client secret if available to get
0034f4
 device code
0034f4
MIME-Version: 1.0
0034f4
Content-Type: text/plain; charset=UTF-8
0034f4
Content-Transfer-Encoding: 8bit
0034f4
0034f4
Some IdP have the concept of confidential client, i.e. clients where the
0034f4
client's secret can be stored safely by the related application. For a
0034f4
confidential client some IdPs expects that the client secret is used in
0034f4
all requests together with the client ID although OAuth2 specs currently
0034f4
only mention this explicitly for the token request. To make sure the
0034f4
device code can be requested in this case the client secret is added to
0034f4
the device code request if the secret is provided.
0034f4
0034f4
Resolves: https://github.com/SSSD/sssd/issues/6146
0034f4
0034f4
Reviewed-by: Justin Stephenson <jstephen@redhat.com>
0034f4
Reviewed-by: Pavel Březina <pbrezina@redhat.com>
0034f4
(cherry picked from commit a4d4617efeff871c5d2762e35f9dec57fa24fb1a)
0034f4
0034f4
Reviewed-by: Alexey Tikhonov <atikhono@redhat.com>
0034f4
---
0034f4
 src/oidc_child/oidc_child.c      |  2 +-
0034f4
 src/oidc_child/oidc_child_curl.c | 12 +++++++++++-
0034f4
 src/oidc_child/oidc_child_util.h |  2 +-
0034f4
 3 files changed, 13 insertions(+), 3 deletions(-)
0034f4
0034f4
diff --git a/src/oidc_child/oidc_child.c b/src/oidc_child/oidc_child.c
0034f4
index aeeac3595..c8d35d5d8 100644
0034f4
--- a/src/oidc_child/oidc_child.c
0034f4
+++ b/src/oidc_child/oidc_child.c
0034f4
@@ -454,7 +454,7 @@ int main(int argc, const char *argv[])
0034f4
     }
0034f4
 
0034f4
     if (opts.get_device_code) {
0034f4
-        ret = get_devicecode(dc_ctx, opts.client_id);
0034f4
+        ret = get_devicecode(dc_ctx, opts.client_id, opts.client_secret);
0034f4
         if (ret != EOK) {
0034f4
             DEBUG(SSSDBG_OP_FAILURE, "Failed to get device code.\n");
0034f4
             goto done;
0034f4
diff --git a/src/oidc_child/oidc_child_curl.c b/src/oidc_child/oidc_child_curl.c
0034f4
index df438e007..6e80c3abf 100644
0034f4
--- a/src/oidc_child/oidc_child_curl.c
0034f4
+++ b/src/oidc_child/oidc_child_curl.c
0034f4
@@ -428,7 +428,7 @@ done:
0034f4
 #define DEFAULT_SCOPE "user"
0034f4
 
0034f4
 errno_t get_devicecode(struct devicecode_ctx *dc_ctx,
0034f4
-                       const char *client_id)
0034f4
+                       const char *client_id, const char *client_secret)
0034f4
 {
0034f4
     int ret;
0034f4
 
0034f4
@@ -443,6 +443,16 @@ errno_t get_devicecode(struct devicecode_ctx *dc_ctx,
0034f4
         return ENOMEM;
0034f4
     }
0034f4
 
0034f4
+    if (client_secret != NULL) {
0034f4
+        post_data = talloc_asprintf_append(post_data, "&client_secret=%s",
0034f4
+                                           client_secret);
0034f4
+        if (post_data == NULL) {
0034f4
+            DEBUG(SSSDBG_OP_FAILURE,
0034f4
+                  "Failed to add client secret to POST data.\n");
0034f4
+            return ENOMEM;
0034f4
+        }
0034f4
+    }
0034f4
+
0034f4
     clean_http_data(dc_ctx);
0034f4
     ret = do_http_request(dc_ctx, dc_ctx->device_authorization_endpoint,
0034f4
                           post_data, NULL);
0034f4
diff --git a/src/oidc_child/oidc_child_util.h b/src/oidc_child/oidc_child_util.h
0034f4
index ae5a72bc2..8b106ae79 100644
0034f4
--- a/src/oidc_child/oidc_child_util.h
0034f4
+++ b/src/oidc_child/oidc_child_util.h
0034f4
@@ -73,7 +73,7 @@ errno_t get_openid_configuration(struct devicecode_ctx *dc_ctx,
0034f4
 errno_t get_jwks(struct devicecode_ctx *dc_ctx);
0034f4
 
0034f4
 errno_t get_devicecode(struct devicecode_ctx *dc_ctx,
0034f4
-                       const char *client_id);
0034f4
+                       const char *client_id, const char *client_secret);
0034f4
 
0034f4
 errno_t get_token(TALLOC_CTX *mem_ctx,
0034f4
                   struct devicecode_ctx *dc_ctx, const char *client_id,
0034f4
-- 
0034f4
2.37.3
0034f4