How OAuth 2.0 works in real life:
So I was driving by Olaf's bakery on my way to work and I saw the most delicious donut in the window, I mean the thing was dripping chocolatey goodness. So I went inside and demanded "I must have that donut!". He said "sure that will be $30."
Yeah I know $30 for one donut! It must be delicious! I reached for my wallet when suddenly I hear the chef yell "NO! No donut for you". I asked why? He said he only accepts bank transfers.
Seriously? Yep, he was serious. I almost walked away right there, but then the donut called out to me "Eat me, I'm delicious...". Who am I to disobey orders from a donut? So I said ok.
He hands me a note with his name on it (the chef not the donut), "Tell them Olaf sent you". His name was on the note, so I don't know what the point of saying that would be, but ok.
So I drive an hour and a half to my bank. I hand the note to the teller, I tell her Olaf sent me. She gives one of those looks, the kind of look that says "I can read".
She takes my note, asks for my id, asks me how much money is ok to give him. I tell her $30 dollars. She does some scribbling and hands me another note. This one has a bunch of numbers on it, I guess that's how they keep track of the notes.
At this point I'm starving. I rush out of there, an hour and a half later I'm back, standing in front of Olaf with my note extended to his face. He takes it, looks it over and says "I'll be back".
I thought he was getting my donut, but after 30 minutes I started to get suspicious. So I asked the guy behind the counter "Where's Olaf?". He says "He went to get money". "What do you mean?", "He take note to bank".
Huh... so Olaf took the note that the bank gave me and went back to the bank to get money out of my account. Since he has the note that the bank gave me, so the bank knows he's the guy I was talking about. And because I spoke with the bank they know to only give him $30.
It must have taken me a long time to figure that out because by the time I looked up, there was Olaf standing in front of me finally handing me my donut. Before I left I had to ask "Olaf, did you always sell donuts this way?", "No, I used to do it different."
Huh. As I walked back to my car my phone rang. I didn't bother answering, it was probably my job calling to fire me, my boss is such a ***. Besides I was caught up thinking about the whole process I just went through.
I mean think about it, I was able to let Olaf take $30 out of my bank account without having to give him my account information. And I didn't have to worry that he would take out too much money because I already told the bank he was only allowed to take $30. And the bank knew he was the right guy because he had the note they gave me to give to Olaf.
Ok, sure I would rather hand him $30 from my pocket. But now that he has that note I could just tell the bank to let him take $30 every week, then I can just show up at the bakery and I don't have to go to the bank anymore. I could even order the donut by phone if I wanted to.
Of course I'd never do that - that donut was disgusting.
I wonder if this approach has broader application. He mentioned this was his second approach, I could call it Olaf 2.0. Anyway I better get home, I gotta start looking for a new job. But not before I get one of those strawberry shakes from that new place across town, I need something to wash away that taste of that donut.
code
) but there are other grant types defined in OAuth 2.0 that are relevant for different use cases (e.g. non-user related ones). – Hans Z. Dec 28 '14 at 21:50