This is happening when a Facebook/Google log in is clicked on an XYZ website.
- XYZ website redirects to Facebook login page together with an XYZclientID(XYZ should be already registered under Facebook as a developer)
- Facebook identifies that XYZ(using XYZclientID) wants to authenticate ABC person
- ABC person log in to facebook.
- Facebook issues an authorisation code(for ABC+XYX combination) and redirects back to XYZ website.
- XYZ uses this authorisation code + XYZclientID + XYZclientSecret to get a bearer token
- Facebook validates the secret and issues a bearer token(linked to ABC person)
- XYZ uses this bearer token to retrieve details of ABC person. (It cannot be used to retrieve data of DEG person)
- Facebook give the email & other personal details of ABC to XYZ and XYZ shows that ABC is logged in.
More elaborated here : https://www.scienceabc.com/innovation/oauth-how-does-login-with-facebook-google-work.html