[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/url-http-oauth e1408ed406 02/24: Implement provider reg
From: |
Thomas Fitzsimmons |
Subject: |
[elpa] externals/url-http-oauth e1408ed406 02/24: Implement provider registration |
Date: |
Mon, 8 May 2023 21:10:43 -0400 (EDT) |
branch: externals/url-http-oauth
commit e1408ed4062f8a3cda9f18d67aeea01e8fc4d4b6
Author: Thomas Fitzsimmons <fitzsim@fitzsim.org>
Commit: Thomas Fitzsimmons <fitzsim@fitzsim.org>
Implement provider registration
* url-http-oauth.el (url-http-oauth--registered-oauth-urls):
Adjust doc string.
(url-http-oauth-url-string): New function.
(url-http-oauth-url-object): Likewise.
(url-http-oauth-register-provider): Likewise.
* url-http-oauth.el (url-oauth-auth): Fix byte compiler warning.
---
url-http-oauth.el | 36 ++++++++++++++++++++++++++++++++++--
1 file changed, 34 insertions(+), 2 deletions(-)
diff --git a/url-http-oauth.el b/url-http-oauth.el
index ba0916d30f..acbd40ffbb 100644
--- a/url-http-oauth.el
+++ b/url-http-oauth.el
@@ -32,15 +32,47 @@
(require 'url-http)
(require 'url-util)
+;; For evaluation during development:
+;; (setq url-http-oauth--registered-oauth-urls nil)
+;; (message "%S" url-http-oauth--registered-oauth-urls)
(defvar url-http-oauth--registered-oauth-urls nil
- "A hash table mapping URL strings to lists of OAuth 2.0 configuration
items.")
+ "A hash table mapping URL strings to lists of OAuth 2.0 configuration.")
+
+(defun url-http-oauth-url-string (url)
+ "Ensure URL is a string."
+ (if (url-p url) (url-recreate-url url) url))
+
+(defun url-http-oauth-url-object (url)
+ "Ensure URL is a parsed URL object."
+ (if (url-p url) url (url-generic-parse-url url)))
+
+;; Maybe if RFC 8414, "OAuth 2.0 Authorization Server Metadata",
+;; catches on, authorize-url and access-token-url can be made
+;; optional, and their values retrieved automatically. But from what
+;; I can tell RFC 8414 is not consistently implemented yet.
+(defun url-http-oauth-register-provider (url authorize-url access-token-url)
+ "Register URL as an OAuth 2.0 provider.
+URL will be accessed by Emacs with a suitable \"Authorization\"
+header containing \"Bearer <token>\". AUTHORIZE-URL and
+ACCESS-TOKEN-URL will be used to acquire <token> and save it to
+the user's `auth-source' file. URL and ACCESS-TOKEN-URL are
+either URL structures or URL strings."
+ (unless url-http-oauth--registered-oauth-urls
+ (setq url-http-oauth--registered-oauth-urls
+ (make-hash-table :test #'equal)))
+ (let ((key (url-http-oauth-url-string url))
+ (authorize (url-http-oauth-url-object authorize-url))
+ (access-token (url-http-oauth-url-object access-token-url)))
+ (puthash key (list authorize access-token)
+ url-http-oauth--registered-oauth-urls)))
;;; Public function called by `url-get-authentication'.
;;;###autoload
(defun url-oauth-auth (url &optional _prompt _overwrite _realm _args)
"Return an OAuth 2.0 HTTP authorization header.
URL is a structure representing a parsed URL."
- nil)
+ ;; Do nothing for now.
+ (when url nil))
;;; Register `url-oauth-auth' HTTP authentication method.
;;;###autoload
- [elpa] externals/url-http-oauth 8601d89d43 18/24: Complete regexp, list and token refresh design, (continued)
- [elpa] externals/url-http-oauth 8601d89d43 18/24: Complete regexp, list and token refresh design, Thomas Fitzsimmons, 2023/05/08
- [elpa] externals/url-http-oauth ee73bb0450 19/24: Make functions private, fix some bugs, Thomas Fitzsimmons, 2023/05/08
- [elpa] externals/url-http-oauth 7e825a8765 21/24: Allow per-provider user-agent interaction function, Thomas Fitzsimmons, 2023/05/08
- [elpa] externals/url-http-oauth 9b2af487e3 22/24: Use relative expiry time in seconds, Thomas Fitzsimmons, 2023/05/08
- [elpa] externals/url-http-oauth d86dbb478d 23/24: Retest against sourcehut, fix new issues, Thomas Fitzsimmons, 2023/05/08
- [elpa] externals/url-http-oauth 4441b79a9a 13/24: Remove explicit extra argument handling, Thomas Fitzsimmons, 2023/05/08
- [elpa] externals/url-http-oauth 085d57961a 20/24: Make message formatting consistent, Thomas Fitzsimmons, 2023/05/08
- [elpa] externals/url-http-oauth 0bf4a7633d 08/24: Complete confidential client support, Thomas Fitzsimmons, 2023/05/08
- [elpa] externals/url-http-oauth b884e725af 05/24: Get basics working for Sourcehut, Thomas Fitzsimmons, 2023/05/08
- [elpa] externals/url-http-oauth 38157dfb3a 09/24: Reduce overloading of "register", Thomas Fitzsimmons, 2023/05/08
- [elpa] externals/url-http-oauth e1408ed406 02/24: Implement provider registration,
Thomas Fitzsimmons <=
- [elpa] externals/url-http-oauth f5b953197b 15/24: Fix auth-source-search for path and scope, Thomas Fitzsimmons, 2023/05/08
- [elpa] externals/url-http-oauth 40c46af10c 24/24: Bump version to 0.8.0, Thomas Fitzsimmons, 2023/05/08
- [elpa] externals/url-http-oauth e95f685771 06/24: Begin auth-source implementation, Thomas Fitzsimmons, 2023/05/08
- [elpa] externals/url-http-oauth 1ecb40b545 17/24: Make some adjustments based on testing, Thomas Fitzsimmons, 2023/05/08
- [elpa] externals/url-http-oauth fcb5929654 16/24: Fix auth-source lookup conflicts and config cdrs, Thomas Fitzsimmons, 2023/05/08