Skip to content

Add Facebook and Google authentication to your HTTP REST API in Actix-web

Notifications You must be signed in to change notification settings

jbham/actix-fb-google-login

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

How does it work?

  • All magic happens in this file on this line
  • 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.

About

Add Facebook and Google authentication to your HTTP REST API in Actix-web

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published