Skip to main content

Module oauth2

Module oauth2 

Source
Expand description

OAuth2 and OpenID Connect (OIDC) Authentication

This module provides OAuth2 2.0 and OpenID Connect authentication support, similar to Spring Security’s OAuth2 Login.

§Features

  • Authorization Code Flow - Standard OAuth2 flow for web applications
  • PKCE Support - Proof Key for Code Exchange for enhanced security
  • OIDC Discovery - Automatic provider configuration via well-known endpoints
  • Multiple Providers - Built-in support for Google, GitHub, Microsoft, etc.
  • Custom Providers - Easy to add custom OAuth2/OIDC providers

§Quick Start

use actix_security_core::http::security::oauth2::{
    OAuth2Config, OAuth2Provider, OAuth2Client
};

// Configure Google OAuth2
let config = OAuth2Config::new(
    "your-client-id",
    "your-client-secret",
    "http://localhost:8080/oauth2/callback/google"
)
.provider(OAuth2Provider::Google)
.scopes(vec!["openid", "email", "profile"]);

let client = OAuth2Client::new(config).await?;

// Generate authorization URL
let (auth_url, csrf_token, nonce) = client.authorization_url();

§Spring Security Comparison

Spring SecurityActix Security
ClientRegistrationOAuth2Config
ClientRegistrationRepositoryOAuth2ClientRepository
OAuth2AuthorizedClientOAuth2Client
OAuth2UserOAuth2User
OidcUserOidcUser

Structs§

AuthorizationRequestState
Authorization request state (stored in session)
IdTokenClaims
ID Token claims
OAuth2Authenticator
OAuth2 authenticator that validates OAuth2 access tokens
OAuth2Client
OAuth2 client for handling authorization flows
OAuth2ClientRepository
Repository for multiple OAuth2 client registrations
OAuth2Config
OAuth2 configuration for a client registration
OAuth2User
User information retrieved from OAuth2 provider
OidcUser
OIDC user with ID token claims

Enums§

OAuth2Error
OAuth2 error types
OAuth2Provider
Common OAuth2/OIDC providers with pre-configured endpoints