FastAPI — Google as an external authentication provider

Nils de Bruin
8 min readMay 10, 2019

Social login

In my last articles (FastAPI — How to add basic and cookie authentication and FastAPI authentication revisited: Enabling API key authentication) I wrote about implementing two kinds of authentication (Basic and API) for FastAPI, which are ‘local’ authentication options. With ‘local’ authentication I mean that a username/password or API key are checked with FastAPI without using an external authentication provider.

This article will cover the case of connecting to an external authentication provider, in this case, Google. With this set-up, you are able to give Google users access to the API. The example code can be leveraged to include other external authentication providers, like for example GitHub or Twitter. This is called social login. To better understand the steps involved, we first start with a description of the challenge.

The challenge

So we want Social login, but where should you start? Luckily, there has been a very interesting discussion on the FastAPI Github page, which can be found here:

--

--