From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Naoya Yamashita Newsgroups: gmane.emacs.devel Subject: [ELPA/oauth2] Use passed id to find plstore entry if specified Date: Fri, 19 Feb 2021 21:02:04 +0900 (JST) Message-ID: <20210219.210204.1316668272453618992.conao3@gmail.com> Mime-Version: 1.0 Content-Type: Multipart/Mixed; boundary="--Next_Part(Fri_Feb_19_21_02_04_2021_134)--" Content-Transfer-Encoding: 7bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="5553"; mail-complaints-to="usenet@ciao.gmane.io" To: emacs-devel@gnu.org, julien@danjou.info Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Fri Feb 19 13:04:25 2021 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lD4WD-0001J1-U2 for ged-emacs-devel@m.gmane-mx.org; Fri, 19 Feb 2021 13:04:22 +0100 Original-Received: from localhost ([::1]:52260 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lD4WC-0006bi-SN for ged-emacs-devel@m.gmane-mx.org; Fri, 19 Feb 2021 07:04:20 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:52298) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lD4UQ-0005LI-64 for emacs-devel@gnu.org; Fri, 19 Feb 2021 07:02:33 -0500 Original-Received: from mail-pl1-x62e.google.com ([2607:f8b0:4864:20::62e]:43125) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lD4UO-0001HT-Eb for emacs-devel@gnu.org; Fri, 19 Feb 2021 07:02:29 -0500 Original-Received: by mail-pl1-x62e.google.com with SMTP id r2so3237415plr.10 for ; Fri, 19 Feb 2021 04:02:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:message-id:to:subject:from:mime-version :content-transfer-encoding; bh=iwrK5ZocOULlB+DX0H/xhXW2i+q8aa0abvuQ8pO6aMc=; b=mOh69HTKO5HL1EFjfvV5aUn7DdwojcgmtwVCbUhdh3iw4vuGfXnILBrJBQCvYayDbf VioR+YSRKvyT7INSYxnC7NmSEAEIlqgamuJAofWRfm05JYY3ZznIac+qtt3WAfFtNOrm w7PYaweZRlM0PUKN1WILTcdUlhlOhsQoK/G/DaRTFomyFgpL6H66OeL1RnYWkY3/TcEh +xCMabouFQca5KWZr5XlJCAke6fNmtKng9FIhQRoZ3G/N9ndhdL3YXeDAK7RnyHhCH7O XE9Pgjqo3wkn3uc3hXQXFmeSCNDQaIzimII0eoMvP7mGeTX2kU68H8Cx36rC8+4YoJjw Y7lA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:to:subject:from:mime-version :content-transfer-encoding; bh=iwrK5ZocOULlB+DX0H/xhXW2i+q8aa0abvuQ8pO6aMc=; b=ZtCornBTeguMakciFwFJTyFuX50WrixsxTF88Nd3TAvA3jbt65WxM57Nq+/j1Y6rH8 s0vBRkMh+qHuM55Z6LmfCuuovd/M+zgVanWNV4V/wGZ/RQoGKIgFUcLCMzDegg2lE6Iv 7Rwk8ZNUxv4ggkwul5Pih5q4Y9480KxDjY8USJ5A1cjUwplgVXxPow85m9fNnbcgQZD3 K8uSxplHtgXaIP2Qt/W3d70KDKFaYvOofjeuencn77rk0Hn5w1x72bKFe+IVaKyZLdGu H/lYRecxH8lYRjVt/8xZFjbL9xCDFYZ0p00Znmyzoz9tCD2RYbFWoTYRJlcxJBKouHuQ Tqwg== X-Gm-Message-State: AOAM5331JxROcAlhBlxKNwsuJ1uKsw0rHb3V69mBakh51wXUmcvRjUqM 3VRAy/tW5090mech618eHKZ5Ae4ZyU1lLQ== X-Google-Smtp-Source: ABdhPJyQoop+VnH+I9cNaZDqb6l4Ge8Xoy5Qk/tEpPGjbMRHvnU65JiYyOs82FfOALts6d5fZZMY8A== X-Received: by 2002:a17:90a:b292:: with SMTP id c18mr8831756pjr.134.1613736146680; Fri, 19 Feb 2021 04:02:26 -0800 (PST) Original-Received: from localhost (p210141-ipngn200407niho.hiroshima.ocn.ne.jp. [118.4.79.141]) by smtp.gmail.com with ESMTPSA id y16sm8767912pgg.20.2021.02.19.04.02.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Feb 2021 04:02:26 -0800 (PST) X-Mailer: Mew version 6.8 on Emacs 27.1 Received-SPF: pass client-ip=2607:f8b0:4864:20::62e; envelope-from=conao3@gmail.com; helo=mail-pl1-x62e.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:265225 Archived-At: ----Next_Part(Fri_Feb_19_21_02_04_2021_134)-- Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit 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 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 ``` ----Next_Part(Fri_Feb_19_21_02_04_2021_134)-- Content-Type: Text/X-Patch; charset=us-ascii Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="0001-packages-oauth2-oauth2.el-Use-client-id-and-secret-t.patch" >From 53bb4d1a55affcdff073febe29b90d19f3603525 Mon Sep 17 00:00:00 2001 From: Naoya Yamashita 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 ----Next_Part(Fri_Feb_19_21_02_04_2021_134)----