passport-strategies

Crates.iopassport-strategies
lib.rspassport-strategies
version0.1.14
sourcesrc
created_at2024-01-19 15:22:27.890416
updated_at2024-08-29 05:40:39.478807
descriptionA thin wrapper on top of oauth2-rs that simplifies oauth2 authentication.
homepage
repositoryhttps://github.com/bob-hawkins/passport-strategies
max_upload_size
id1105392
size70,219
Bob Hawkins (bob-hawkins)

documentation

README

Passport strategies

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.

Adding passport-strategies

passport-strategies = { version = "0.1.11" }

Usage

Create an Application

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.

Configure Strategy

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.

Example (Microsoft)

 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.

What's new

  1. Support for the axum web framework.
  2. Reddit Strategy integration.
  3. Remove of the logic error in previous versions when multiple users try to authenticate at the same time.
  4. Clearing the nolonger needed verifiers from the memory
Commit count: 0

cargo fmt