Replace core login function
I believe what you're trying to accomplish can be done with a plugin.

Perhaps this OAuth plugin could at least offer some boilerplate for you: https://dukt.net/craft/oauth/

dukt's github also has some provider-specific plugins: https://github.com/dukt