সহজ ভাষায় oAuth 2.0

Scroll this

অনলাইনে আমরা প্রায়শই বিভিন্ন ওয়েবসাইটে দেখে থাকি ‘Login with facebook/google/github’ এমন অপশন।

অথবা, বিভিন্ন ওয়েবসাইট অথবা অ্যাপ এ ফাইল এটাচ করার জন্য দেখি ‘attach file from google drive/dropbox’ এমন অপশন ।

ইন্টারনেটে যে বিশেষ protocol বা framework ব্যবহার এর মাধ্যমে এক এপ্লিকেশন “সিকিউরিটি বজায় রেখে” , আরেক এপ্লিকেশনের resource/data এরকমভাবে access করে – তার নাম হচ্ছে oAuth 2.0 ।
আজকে, সহজ ভাষায় আমরা oAuth2.0 কি এবং কিভাবে কাজ করে সেটা বোঝার চেষ্টা করব :

১) User এর কিছু data আছে

২) User এর data কে ম্যানেজ করার জন্য একটা Server আছে। এটা হল “Resource Server”

৩) আরেকটি Application এর কোন কারনে সেই user এর data কে ব্যবহার করা দরকার । এটা হল Client Application

৪) User এর data কে ঢুকানো/বের করার জন্য একটা gate/interface দরকার। এই গেইট কে ইন্টারনেটের ভাষায় বলে API

৫) client application user data পাবার জন্য request করে . Resource Server এর কাছে

৬) resource server user এর data কে ফেরত দেয়

৭) আচ্ছা , client application টা যদি কোন malicious application হয় তখন কি হবে ?

৮) Resource server তখনও user data কে return করবে । অর্থাৎ malicious application তখন user data পেয়ে যাবে

৯) আমাদের এই ঘটনা প্রতিহত করার জন্য একটা ব্যবস্থা থাকা দরকার

১০) প্রাথমিক ব্যবস্থা : সঠিক client application কে আগে থেকে একটি access token দিয়ে রাখা যেতে পারে । access token টি পরবর্তীতে প্রমান করবে যে, client application টির user data পাবার permission আছে ।

১১) এখন client application যখনই user data এর জন্য request করে তখন access token সহ request করে

১২) Resource Server সেই access token কে verify করে।

১৩) ঠিকভাবে verification সম্পন্ন হলেই কেবল client application কে resource server , user data দেয়

১৪) কিন্তু, এই access token তো কাউকে আগে তৈরি করতে হবে আগে তাইনা ?

১৫) যে access token তৈরি করে তাকে বলে , Authorization Server

১৬) authorization server প্রথম এই access token তৈরি করে …

১৭) তারপর সে এই access token দেয় client application কে

১৮) আচ্ছা, এখন আমরা একটু রিভিউ করি । আমাদের মুলত ৩ টা পক্ষ আছে : একটি “Authorization Server”, একটি “Client Application” , এবং একটি “Resource Server”

১৯) Authorization Server প্রথমে access token তৈরি করে Client Application কে দেয়

২০) Client application তারপর user data পাবার জন্য access token সমেত Resource Server কে request করে

২১) Resource Server সেই access token এর user data পাবার permission যাচাই করে দেখে

২২) সবকিছু ঠিকঠাক থাকলে Resource Server , Client Application কে user data ফেরত দেয়

২৩) উপরের flow তে, প্রথম ধাপ ছিল access token তৈরি করা। কিন্তু, বাস্তব ক্ষেত্রে token তৈরির আগে আরও একটা ধাপ থাকে। token তৈরির আগে user এর কাছে অনুমতি নেয়ার একটা ধাপ থাকে

২৪) প্রথমে Client application টি access token তৈরির জন্য request করে Authorization Server কে

২৫) তারপর authorization server , user কে জিজ্ঞাসা করে যে এই client application কে তার user data পাবার permission দিবে কিনা

২৬)  authorization server তখন access token তৈরি করে

২৭) এবং সেই access token টি client application কে দেয়

২৮) হলুদ উপবৃত্তাকার অংশটির দিকে খেয়াল করুন একটু । এখানে মুলত একটি access token এর request, এবং সেই request এর response থাকে।

২৯) “OAuth 2.0” আসলে এই অংশটাকে standardize করেছে . OAuth 2.0 এর পুরো technical detail পাওয়া যাবে RFC 6749 (The OAuth 2.0 Authorization Framework) এ

References:
1) https://tools.ietf.org/html/rfc6749
2) https://medium.com/@darutk/the-simplest-guide-to-oauth-2-0-8c71bd9a15bb
3) http://w3programmers.com/bangla/what-is-oauth/
4) https://www.digitalocean.com/community/tutorials/an-introduction-to-oauth-2

18 Comments

  1. Very good writeup. Will be really helpful for the basic.

    If possible, can you fit this anywhere in this post, that its actually authorizing some application to access your data. Maybe somewhere in the point #1. But of course if you feel it appropriate.

    • I will put it in the beginning. Thanks for the feedback dost. Love you ^_^

  2. It was a great article. The description is so simple and intuitive. I finally understand the authentication process that I actually do every day but never knew the details. This was a really interesting thing to learn! Thank you Bhaia. Keep up the great work! 😀

    • Thank you sifat. Humbled by the kind words brother. However, oauth2.0 is an authorization process- not an authentication process.

  3. Nice writeup. One thing to add btw, when resource server gets the access token, it internally handshakes with auth server to confirm the validity and permission of that access token. For access token validity and ACL auth service is always the source of truth.

    Another thing to add as a nice to have btw, that the client app has to be registered like an entity with auth service beforehand- so that auth service recognise the app and initiate the process of getting user consent on behalf and eventually issue a valid access token.

    I believe if these two are added to the flow, then it can be presented as a great easy to understand oauth 2.0 explanation!

    • Great inputs dost. I will edit & add the second point in the description.

  4. খুবই গোছান ও সহজ আর্টিকেল।

  5. Just right amount of info!
    I believe a 6 year old can understand the steps as you described.
    Got a craving for the sequel of this topic….
    “How the authorization server authenticates and authorizes for the token?”

  6. Getting started হিসাবে খুবই ভালো হয়েছে। আর চিত্রের মাধ্যমে সকল স্টেপ দেখানো হওয়ায় সবার জন্য বোঝা সহজ হবে। খুবই সংক্ষিপ্ত ভাষায় গুছিয়ে সুন্দর উপস্থাপন।

    • ধন্যবাদ আবরার । তুমিও লেখা শুরু করতে পারো কিন্তু

Submit a comment

Your email address will not be published. Required fields are marked *