emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/url-http-oauth-demo de81100f6e 04/13: Finish confidenti


From: Thomas Fitzsimmons
Subject: [elpa] externals/url-http-oauth-demo de81100f6e 04/13: Finish confidential client demonstration
Date: Mon, 8 May 2023 21:25:11 -0400 (EDT)

branch: externals/url-http-oauth-demo
commit de81100f6ea0a1d375998706a8b0b9d355ee0e1d
Author: Thomas Fitzsimmons <fitzsim@fitzsim.org>
Commit: Thomas Fitzsimmons <fitzsim@fitzsim.org>

    Finish confidential client demonstration
    
    * url-http-oauth-demo.el: Add usage section to comment header.
    Remove scope registration argument.
    (url-http-oauth-demo-get-api-version): Remove function.
    (url-http-oauth-demo-get-profile-name): Create URL object from
    individual slots.  Adjust message and return value.
---
 url-http-oauth-demo.el | 56 ++++++++++++++++++++++++++------------------------
 1 file changed, 29 insertions(+), 27 deletions(-)

diff --git a/url-http-oauth-demo.el b/url-http-oauth-demo.el
index 5b13e0bd91..0ab1598b0c 100644
--- a/url-http-oauth-demo.el
+++ b/url-http-oauth-demo.el
@@ -23,12 +23,16 @@
 ;;; Commentary:
 ;;
 ;; This package demonstrates an OAuth 2.0 flow for Sourcehut using the
-;; built-in GNU Emacs URL library and the GNU ELPA url-http-oauth
-;; package.
+;; built-in GNU Emacs URL library and the url-http-oauth package.
 ;;
 ;; Installation:
 ;;
 ;; M-x package-install RET url-http-oauth-demo RET
+;;
+;; Usage:
+;;
+;; M-x url-http-oauth-demo-get-profile-name RET
+;; M-: (url-http-oauth-demo-get-profile-name) RET
 
 ;;; Code:
 (require 'url-http-oauth)
@@ -40,44 +44,42 @@
                                   "https://meta.sr.ht/oauth2/authorize";
                                   "https://meta.sr.ht/oauth2/access-token";
                                   "107ba4a9-2a96-4420-8818-84ec1f112405"
-                                  "meta.sr.ht/PROFILE:RO"
                                   'prompt)
 
-;;;###autoload
-(defun url-http-oauth-demo-get-api-version ()
-  "Asynchronously retrieve the Sourcehut GraphQL API version.
-Print the HTTP status and response in *Messages*."
-  (interactive)
-  (let ((url-request-method "POST")
-        (url-request-extra-headers
-         (list (cons "Content-Type" "application/json")
-               (cons "Authorization" "Bearer abcd")))
-        (url-request-data
-         "{\"query\": \"{ version { major, minor, patch } }\"}"))
-    (url-retrieve "https://meta.sr.ht/query";
-                  (lambda (status)
-                    (message "GET-API-VERSION: %S, %S"
-                             status (buffer-string))))))
-
 ;;;###autoload
 (defun url-http-oauth-demo-get-profile-name ()
   "Asynchronously retrieve the Sourcehut profile name.
-Print the result to *Messages*."
+Print the result to *Messages*.  Return the name."
   (interactive)
   (let ((url-request-method "POST")
         (url-request-extra-headers
          (list (cons "Content-Type" "application/json")))
         (url-request-data
          "{\"query\": \"{ me { canonicalName } }\"}"))
-    (with-current-buffer (url-retrieve-synchronously 
"https://meta.sr.ht/query";)
-      (message "GET-PROFILE-NAME: %s" (buffer-string))
+    (with-current-buffer
+        (url-retrieve-synchronously
+         (url-parse-make-urlobj
+          "https"             ; type
+          "fitzsim"           ; user
+          nil                 ; password, resolved by url-http-oauth
+          "meta.sr.ht"        ; host
+          443                 ; port
+          (concat "/query"    ; path
+                  "?"         ; scope:
+                  (url-build-query-string
+                   (list
+                    (list "scope" "meta.sr.ht/PROFILE:RO"))))
+          nil nil t))
       (goto-char (point-min))
       (re-search-forward "\n\n")
-      (let* ((result (json-parse-buffer))
-             ;;(me (gethash "me" result))
-             ;;(name me)
-             )
-        (message "GET-PROFILE-NAME PARSED: %S" result)))))
+      (message "%s" (buffer-substring (point) (point-max)))
+      (gethash
+       "canonicalName"
+       (gethash
+        "me"
+        (gethash
+         "data"
+         (json-parse-buffer)))))))
 
 (provide 'url-http-oauth-demo)
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]