]> git.ipfire.org Git - thirdparty/cups.git/commitdiff
Update client code to issue proper Bearer response, potentially with an error
authorMichael R Sweet <msweet@msweet.org>
Tue, 15 Apr 2025 17:51:22 +0000 (13:51 -0400)
committerMichael R Sweet <msweet@msweet.org>
Tue, 15 Apr 2025 17:51:22 +0000 (13:51 -0400)
message.  Still need to hook everything up...

scheduler/client.c
scheduler/client.h

index 9028c753767048db5d085a68ec66fb4e23c4f387..d10cce365275986bd404807896653d5a8acf78b1 100644 (file)
@@ -2101,7 +2101,7 @@ cupsdSendHeader(
     char           *type,              /* I - MIME type of document */
     int            auth_type)          /* I - Type of authentication */
 {
-  char         auth_str[1024];         /* Authorization string */
+  char         auth_str[2048];         /* Authorization string */
 
 
   cupsdLogClient(con, CUPSD_LOG_DEBUG2, "cupsdSendHeader: code=%d, type=\"%s\", auth_type=%d", code, type, auth_type);
@@ -2139,6 +2139,26 @@ cupsdSendHeader(
     {
       cupsCopyString(auth_str, "Basic realm=\"CUPS\"", sizeof(auth_str));
     }
+    else if (auth_type == CUPSD_AUTH_BEARER)
+    {
+     /*
+      * OAuth/OpenID:
+      *
+      * Bearer realm="OAUTH-URI" [scope="SCOPES"] [error="invalid_token" error_description="ERROR"]
+      */
+
+      char     *auth_ptr;              /* Pointer into auth string */
+
+      snprintf(auth_str, sizeof(auth_str), "Bearer realm=\"%s\"", OAuthServer);
+      auth_ptr = auth_str + strlen(auth_str);
+      if (OAuthScopes)
+      {
+        snprintf(auth_ptr, sizeof(auth_str) - (size_t)(auth_ptr - auth_str), " scope=\"%s\"", OAuthScopes);
+        auth_ptr += strlen(auth_ptr);
+      }
+      if (con->autherror[0])
+        snprintf(auth_ptr, sizeof(auth_str) - (size_t)(auth_ptr - auth_str), " error=\"invalid_token\" error_description=\"%s\"", con->autherror);
+    }
     else if (auth_type == CUPSD_AUTH_NEGOTIATE)
     {
       cupsCopyString(auth_str, "Negotiate", sizeof(auth_str));
index 0498c7e2556ebd7caf114417f7f48bd70dec1a77..bd979bfc02d0e67fae14b4fe035d810dd7ea03fb 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Client definitions for the CUPS scheduler.
  *
- * Copyright © 2020-2024 by OpenPrinting.
+ * Copyright © 2020-2025 by OpenPrinting.
  * Copyright © 2007-2018 by Apple Inc.
  * Copyright © 1997-2007 by Easy Software Products, all rights reserved.
  *
@@ -34,6 +34,12 @@ struct cupsd_client_s
                                        /* Username from Authorization: line */
                        password[HTTP_MAX_VALUE],
                                        /* Password from Authorization: line */
+                       email[HTTP_MAX_VALUE],
+                                       /* EMail from OAuth Bearer token */
+                       realname[HTTP_MAX_VALUE],
+                                       /* Real name from OAuth Bearer token */
+                       autherror[HTTP_MAX_VALUE],
+                                       /* Authorization error, if any */
                        uri[HTTP_MAX_URI],
                                        /* Localized URL/URI for GET/PUT */
                        *filename,      /* Filename of output file */