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 Security | Actix Security |
|---|---|
ClientRegistration | OAuth2Config |
ClientRegistrationRepository | OAuth2ClientRepository |
OAuth2AuthorizedClient | OAuth2Client |
OAuth2User | OAuth2User |
OidcUser | OidcUser |
Structs§
- Authorization
Request State - Authorization request state (stored in session)
- IdToken
Claims - ID Token claims
- OAuth2
Authenticator - OAuth2 authenticator that validates OAuth2 access tokens
- OAuth2
Client - OAuth2 client for handling authorization flows
- OAuth2
Client Repository - Repository for multiple OAuth2 client registrations
- OAuth2
Config - OAuth2 configuration for a client registration
- OAuth2
User - User information retrieved from OAuth2 provider
- Oidc
User - OIDC user with ID token claims
Enums§
- OAuth2
Error - OAuth2 error types
- OAuth2
Provider - Common OAuth2/OIDC providers with pre-configured endpoints