unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* [ELPA/oauth2] Use passed id to find plstore entry if specified
@ 2021-02-19 12:02 Naoya Yamashita
  0 siblings, 0 replies; only message in thread
From: Naoya Yamashita @ 2021-02-19 12:02 UTC (permalink / raw)
  To: emacs-devel, julien

[-- 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


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2021-02-19 12:02 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-19 12:02 [ELPA/oauth2] Use passed id to find plstore entry if specified Naoya Yamashita

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).