Add Facebook and Google authentication to your HTTP REST API in Actix-web
Shell 0.37%Rust 95.02%PLpgSQL 4.61%
actix-fb-google-login's Introduction
I created this project while learning Rust. Project shows how to handle Facebook and Google token verification in Rust using Actix-Web. Hope this helps somebody out there.
Next, include AuthenticatedUser struct in your routes like this on line 9
Under the hood, it uses google-jwt-verify library to verify Google Sign-in token and uses reqwest to verify Facebook token. Once verified, it stores the token details in Redis with auto expiration time based on the token expiration time.
How to use?
Make sure to add Google client ID, Facebook details in .env file. Once .env file is filled, this data should seamlessly flow to the rest of the application.
User would authenticate using Google Sign in or Facebook Login in the browser.
Browser would submit either google or facebook token in Authorization header of the HTTP request
Actix will verify the token and proceed depending on whether token is valid/invalid. If invalid, returns 401 error. If valid, it proceeds with rest of the steps.
For this App, all GET requests are non-authenticated so they are allowed without any verification.
Note: Instead of using google-jwt-verify crate, this project uses a local forked copy of it. I simply modified to handle Async mutation in the library. Similar changes were submitted by other user. Hence, I kept my changes local. All credits go to the author of this library.