Crates.io | passport-strategies |
lib.rs | passport-strategies |
version | 0.1.14 |
source | src |
created_at | 2024-01-19 15:22:27.890416 |
updated_at | 2024-08-29 05:40:39.478807 |
description | A thin wrapper on top of oauth2-rs that simplifies oauth2 authentication. |
homepage | |
repository | https://github.com/bob-hawkins/passport-strategies |
max_upload_size | |
id | 1105392 |
size | 70,219 |
Passport strategies for authenticating with Discord, 42, Facebook, Reddit, Google, Microsoft and Github using the OAuth 2.0 API. This library is a thin wrapper of oauth2
that simplifies authentication.
This module lets you authenticate with the above mentioned providers in your applications. By plugging into passport-strategies, (Discord, Microsoft, Google, 42, Reddit, Github and Facebook) authentication can be easily and unobtrusively integrated into any rust application or rust framework.
passport-strategies
passport-strategies = { version = "0.1.11" }
Before using passport-strategies, you must register an application with the respective provider. If you have not already done so, a new application can be created at Facebook
, Google
, Github
, Microsoft
, Reddit
, Discord
and 42
. Your application will be issued an app ID and app secret, which need to be provided to the strategy. You will also need to configure a redirect URI which matches the route in your application.
The passport-strategies
authenticates users using the desired provider account and OAuth 2.0 tokens. The app ID(or in some cases client id)
, redirect url
and client secret
obtained when creating an application are supplied as requirements when creating the strategy. You do not need to provide the authorization url and token url.Unlike passportjs
, the strategy does not require a verify callback, which receives the access token and optional refresh token, as well as profile which contains the authenticated user's provider profile. Instead, the profile, the access token and optional refresh token is returned to complete authentication.
use passport_strategies::strategies::MicrosoftStrategy;
use passport_strategies::passport::Passport;
let passport = Passport::default()
.redirect_urls(passport_strategies::passport::Redirect::new(
"http://localhost:<redirect_url_port>/signup",
"http://localhost:<redirect_url_port>/success",
)?)
.strategize(
Choice::Microsoft,
MicrosoftStrategy::new(
"<client_id>",
"<client_secret>",
&["user.read"],
"<redirect_url>",
),
)?;
See here
for more examples.