Service Account (JWT) का उपयोग करके Google Calendar API इस्तेमाल करने का तरीका
(kibua20.tistory.com)Google API का उपयोग करने के लिए OAuth 2.0 authentication पाने के तरीकों में से, यह JWT (JSON Web Token) का उपयोग करने वाली Service account authentication विधि और Google Calendar API के माध्यम से user account के calendar event प्राप्त करने का तरीका समझाता है.
Service Account का उपयोग करने के लिए नीचे दिए गए 5 चरणों में आगे बढ़ना होगा.
-
Google API console में Service Account बनाएं:
- Service account बनाने पर Client ID और Private Key आवंटित किए जाते हैं.
2, JWT (Json Web Token) बनाएं:
-
Header, Claim set, signature को base64urlsafe मान के रूप में encode करें.
-
Python के मामले में PyJWT से JWT string बनाई जा सकती है.
-
Google authentication server पर JWT का उपयोग करके Token request करें.
-
Google server response के रूप में Access Token देता है.
-
Access token का उपयोग करके Google API को call करें.
Google Calendar API में ध्यान देने वाली बात यह है कि user account और service account अलग-अलग account होते हैं, इसलिए user account के Google Calendar में service account के sharing permission जोड़ने होंगे. Google Calendar API call curl कमांड या Python requests का उपयोग करके की जा सकती है.
2 टिप्पणियां
हम्म.. अगर इसे वास्तव में किसी service में लागू करना हो, तो लगता है कि ऐसा UX बनाना पड़ेगा जिसमें user calendar share करे; क्या यह संभव होगा?
चूंकि यूज़र अकाउंट से कैलेंडर share करना होता है, इसलिए jwt की बजाय oautho2 client ज़्यादा उपयुक्त लगता है.
यह Gmail को oautho2 से implement करने का एक उदाहरण है.
https://kibua20.tistory.com/m/70