unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Naoya Yamashita <conao3@gmail.com>
To: emacs-devel@gnu.org, julien@danjou.info
Subject: [ELPA/oauth2] Use passed id to find plstore entry if specified
Date: Fri, 19 Feb 2021 21:02:04 +0900 (JST)	[thread overview]
Message-ID: <20210219.210204.1316668272453618992.conao3@gmail.com> (raw)

[-- Attachment #1: Type: Text/Plain, Size: 2854 bytes --]


Hi, julien and all.

I want to use your oauth2 package for my package.  It is API
wrapper library and it is designed to use from more other
packages.

oauth2.el <- google-calendar-api.el <- org-gcal.el
                                    \_ calfw-gcal.el
                                    \_ mhc-gcal.el
                                    \_ ...

(This ascii art indicates (`org-gcal`, `calfw-gcal`, `mhc-gcal`
and more) are depends on `google-calendar-api` and it depends on
`oauth2`.)

Now, plstore entry id is computed by below sexp, users cannot
store two or more token for same `oath-url`, `token-url`,
`scope`.

> (defun oauth2-compute-id (auth-url token-url scope)
>   "Compute an unique id based on URLs.
> This allows to store the token in an unique way."
>   (secure-hash 'md5 (concat auth-url token-url scope)))

My patch will add the ability to search and save by id if one is
given.  This will allow multiple independent packages of the same
API to store tokens properly.

(I thought about adding cliend-id to calculate the id, but
rejected it because it is not desirable to change the already
stored id. However, if you think it's a good idea, I'm fine with
it.)

below diff is rejected by me, but you can commit if you fine.

```
From 53bb4d1a55affcdff073febe29b90d19f3603525 Mon Sep 17 00:00:00 2001
From: Naoya Yamashita <conao3@gmail.com>
Date: Fri, 19 Feb 2021 20:25:36 +0900
Subject: [PATCH] * packages/oauth2/oauth2.el: Use client-id and secret to
 compute id

(oauth2-compute-id): Add client-id client-secret as new argument
to compute plstore unique id.
(oauth2-auth-and-store): Fix the function usage.
---
 oauth2.el | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/oauth2.el b/oauth2.el
index 0099e06217..519ff46d17 100644
--- a/oauth2.el
+++ b/oauth2.el
@@ -158,17 +158,17 @@ TOKEN should be obtained with `oauth2-request-access'."
   :group 'oauth2
   :type 'file)
 
-(defun oauth2-compute-id (auth-url token-url scope)
+(defun oauth2-compute-id (auth-url token-url scope &optional client-id client-secret)
   "Compute an unique id based on URLs.
 This allows to store the token in an unique way."
-  (secure-hash 'md5 (concat auth-url token-url scope)))
+  (secure-hash 'md5 (concat auth-url token-url scope client-id client-secret)))
 
 ;;;###autoload
 (defun oauth2-auth-and-store (auth-url token-url scope client-id client-secret &optional redirect-uri state)
   "Request access to a resource and store it using `plstore'."
   ;; We store a MD5 sum of all URL
   (let* ((plstore (plstore-open oauth2-token-file))
-         (id (oauth2-compute-id auth-url token-url scope))
+         (id (oauth2-compute-id auth-url token-url scope client-id client-secret))
          (plist (cdr (plstore-get plstore id))))
     ;; Check if we found something matching this access
     (if plist
-- 
2.30.0
```

[-- Attachment #2: 0001-packages-oauth2-oauth2.el-Use-client-id-and-secret-t.patch --]
[-- Type: Text/X-Patch, Size: 1602 bytes --]

From 53bb4d1a55affcdff073febe29b90d19f3603525 Mon Sep 17 00:00:00 2001
From: Naoya Yamashita <conao3@gmail.com>
Date: Fri, 19 Feb 2021 20:25:36 +0900
Subject: [PATCH] * packages/oauth2/oauth2.el: Use client-id and secret to
 compute id

(oauth2-compute-id): Add client-id client-secret as new argument
to compute plstore unique id.
(oauth2-auth-and-store): Fix the function usage.
---
 oauth2.el | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/oauth2.el b/oauth2.el
index 0099e06217..519ff46d17 100644
--- a/oauth2.el
+++ b/oauth2.el
@@ -158,17 +158,17 @@ TOKEN should be obtained with `oauth2-request-access'."
   :group 'oauth2
   :type 'file)
 
-(defun oauth2-compute-id (auth-url token-url scope)
+(defun oauth2-compute-id (auth-url token-url scope &optional client-id client-secret)
   "Compute an unique id based on URLs.
 This allows to store the token in an unique way."
-  (secure-hash 'md5 (concat auth-url token-url scope)))
+  (secure-hash 'md5 (concat auth-url token-url scope client-id client-secret)))
 
 ;;;###autoload
 (defun oauth2-auth-and-store (auth-url token-url scope client-id client-secret &optional redirect-uri state)
   "Request access to a resource and store it using `plstore'."
   ;; We store a MD5 sum of all URL
   (let* ((plstore (plstore-open oauth2-token-file))
-         (id (oauth2-compute-id auth-url token-url scope))
+         (id (oauth2-compute-id auth-url token-url scope client-id client-secret))
          (plist (cdr (plstore-get plstore id))))
     ;; Check if we found something matching this access
     (if plist
-- 
2.30.0


                 reply	other threads:[~2021-02-19 12:02 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210219.210204.1316668272453618992.conao3@gmail.com \
    --to=conao3@gmail.com \
    --cc=emacs-devel@gnu.org \
    --cc=julien@danjou.info \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).