@@ 5,7 5,7 @@
;; Author: Thomas Fitzsimmons <fitzsim@fitzsim.org>
;; Version: 1.0.2
;; Keywords: comm, data, processes, hypermedia
-;; Package-Requires: ((url-http-oauth "0.8.1")
+;; Package-Requires: ((url-http-oauth "0.8.1")
;; (emacs "27.1")) ; for json-parse-buffer
;;
;; This program is free software; you can redistribute it and/or modify
@@ 102,46 102,44 @@
;;; Code:
(require 'url-http-oauth)
-;;; Tell Emacs that the URL "https://meta.sr.ht/query" uses OAuth 2.0
-;;; for authentication and authorization.
-;;;###autoload
-(url-http-oauth-interpose
- '(;; The client identifier. Replace
- ;; "00000000-0000-0000-0000-000000000000" with a new client
- ;; identifier generated by the user, or by the Emacs library
- ;; developer, at "https://meta.sr.ht/oauth2/client-registration".
- ("client-identifier" . "00000000-0000-0000-0000-000000000000")
- ;; The URL at which the `url-http-oauth-demo' package will access
- ;; resources. Everything that follows is for authentication and
- ;; authorization to satisfy OAuth 2.0 requirements.
- ("resource-url" . "https://meta.sr.ht/query")
- ;; The authorization and token endpoints, published in
- ;; "https://man.sr.ht/meta.sr.ht/oauth.md". There is no way to
- ;; autodiscover them from "https://meta.sr.ht/query".
- ("authorization-endpoint" . "https://meta.sr.ht/oauth2/authorize")
- ("access-token-endpoint" . "https://meta.sr.ht/oauth2/access-token")
- ;; The list of features to which Emacs is requesting the server
- ;; grant it access.
- ("scope" . "meta.sr.ht/PROFILE:RO")
- ;; The client secret, which will be generated as part of client
- ;; registration, at
- ;; "https://meta.sr.ht/oauth2/client-registration". If the user
- ;; generates the client secret, they should note it down. If the
- ;; Emacs library developer generates it, they should make it
- ;; available to the users of their library somehow. In either
- ;; case, Emacs will prompt for it, and store it, ideally
- ;; GPG-encrypted, using `auth-source'. An example client secret
- ;; string is "CeuivTBzZbqJ4iTc+VEdPZJODkBHhuCj4bIqQQAONYaOUGubNM0yG
- ;; ZU3P7ant959W1RkzgvXSeNf2mdxuk5EfA==". The user would paste this
- ;; 88 character client secret string into the minibuffer when
- ;; prompted.
- ("client-secret-method" . prompt)))
-
-;;;###autoload
(defun url-http-oauth-demo-get-profile-name ()
"Asynchronously retrieve the Sourcehut profile name.
Print the result to *Messages*. Return the name."
(interactive)
+ (unless (url-http-oauth-interposed-p "https://meta.sr.ht/query")
+ ;; Tell Emacs that the URL "https://meta.sr.ht/query" uses OAuth
+ ;; 2.0 for authentication and authorization.
+ (url-http-oauth-interpose
+ '(;; The client identifier. Replace
+ ;; "00000000-0000-0000-0000-000000000000" with a new client
+ ;; identifier generated by the user, or by the Emacs library
+ ;; developer, at "https://meta.sr.ht/oauth2/client-registration".
+ ("client-identifier" . "00000000-0000-0000-0000-000000000000")
+ ;; The URL at which the `url-http-oauth-demo' package will access
+ ;; resources. Everything that follows is for authentication and
+ ;; authorization to satisfy OAuth 2.0 requirements.
+ ("resource-url" . "https://meta.sr.ht/query")
+ ;; The authorization and token endpoints, published in
+ ;; "https://man.sr.ht/meta.sr.ht/oauth.md". There is no way to
+ ;; autodiscover them from "https://meta.sr.ht/query".
+ ("authorization-endpoint" . "https://meta.sr.ht/oauth2/authorize")
+ ("access-token-endpoint" . "https://meta.sr.ht/oauth2/access-token")
+ ;; The list of features to which Emacs is requesting the server
+ ;; grant it access.
+ ("scope" . "meta.sr.ht/PROFILE:RO")
+ ;; The client secret, which will be generated as part of client
+ ;; registration, at
+ ;; "https://meta.sr.ht/oauth2/client-registration". If the user
+ ;; generates the client secret, they should note it down. If the
+ ;; Emacs library developer generates it, they should make it
+ ;; available to the users of their library somehow. In either
+ ;; case, Emacs will prompt for it, and store it, ideally
+ ;; GPG-encrypted, using `auth-source'. An example client secret
+ ;; string is "CeuivTBzZbqJ4iTc+VEdPZJODkBHhuCj4bIqQQAONYaOUGubNM0yG
+ ;; ZU3P7ant959W1RkzgvXSeNf2mdxuk5EfA==". The user would paste this
+ ;; 88 character client secret string into the minibuffer when
+ ;; prompted.
+ ("client-secret-method" . prompt))))
(let ((url-request-method "POST")
(url-request-extra-headers
(list (cons "Content-Type" "application/json")))