I got it work after clearing my thoughts here. There weren’t any problem with the code. Problem was my understanding of how OAuth works.
I had not properly logged out myself from the Github account and that is why the access was not revoked after logout.
I will still leave this here.