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

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