2 पॉइंट द्वारा kibua20 2020-07-12 | 2 टिप्पणियां | WhatsApp पर शेयर करें

Google API का उपयोग करने के लिए OAuth 2.0 authentication पाने के तरीकों में से, यह JWT (JSON Web Token) का उपयोग करने वाली Service account authentication विधि और Google Calendar API के माध्यम से user account के calendar event प्राप्त करने का तरीका समझाता है.

Service Account का उपयोग करने के लिए नीचे दिए गए 5 चरणों में आगे बढ़ना होगा.

  1. 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 बनाई जा सकती है.

  1. Google authentication server पर JWT का उपयोग करके Token request करें.

  2. Google server response के रूप में Access Token देता है.

  3. 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 टिप्पणियां

 
galadbran 2020-07-13

हम्म.. अगर इसे वास्तव में किसी service में लागू करना हो, तो लगता है कि ऐसा UX बनाना पड़ेगा जिसमें user calendar share करे; क्या यह संभव होगा?

 
kibua20 2020-07-13

चूंकि यूज़र अकाउंट से कैलेंडर share करना होता है, इसलिए jwt की बजाय oautho2 client ज़्यादा उपयुक्त लगता है.

यह Gmail को oautho2 से implement करने का एक उदाहरण है.

https://kibua20.tistory.com/m/70