oxide-auth
repository·master·Indexed 21 days ago
https://github.com/197g/oxide-authA modular OAuth2 server library for Rust (v0.6.1) featuring a trait-based interface for managing tokens. It is designed to be server-agnostic with configurable and pluggable backends, providing official integration crates for web frameworks including actix-web, axum, rocket, poem, iron, and rouille, as well as async/await and redis support.
What's inside oxide-auth
- oxide-auth is an OAuth2 server library designed to manage OAuth2 tokens on a server. It is built to be highly extensible and agnostic of the specific web server being used. The core library provides a trait-based interface that allows you to plug in different front-end web servers and back-end storage systems easily.
Integrate oxide-auth with the Poem web server
masterTheoxide-auth-poemcrate provides integration between theoxide-authauthentication framework and thepoemweb server library. This allows you to useoxide-auth's authentication logic within a Poem-based web application.Integrate oxide-auth with the Rouille web server
masterTheoxide-auth-rouillecrate provides integration between theoxide-authauthentication framework and therouilleweb server library. This allows you to implement authentication flows within a Rouille-based web application.Integrate oxide-auth with Axum
masteroxide-auth-axumprovides integration between theoxide-authauthentication framework and theaxumweb server library. This allows you to useoxide-auth's authentication logic within Axum-based web applications.Integrate oxide-auth with the Rocket web server
masterTheoxide-auth-rocketcrate provides integration between theoxide-authauthentication framework and therocketweb server library. This allows you to useoxide-auth's authentication logic within a Rocket-based application.Integrate oxide-auth with async/await
masterTheoxide-auth-asynccrate provides integration for the coreoxide-authlibrary, allowing you to use its authentication logic withinasync fncontexts and with Rustfutures.Integrate oxide-auth with the Iron web server
masterTheoxide-auth-ironcrate provides integration between theoxide-authauthentication framework and theironweb server library. This allows you to useoxide-auth's authentication logic within an Iron-based web application.Integrate oxide-auth with actix-web
masterTheoxide-auth-actixcrate provides integration between the coreoxide-authlibrary and theactix-webframework. It allows you to leverage the actor model and web request handling ofactix-webto implement authentication flows provided byoxide-auth.Integrate oxide-auth with web frameworks and databases
masterWhile the core
oxide-authcrate is server-agnostic, several extension crates provide idiomatic wrappers for popular Rust web frameworks and database backends. These extensions implement the necessaryoxide-authtraits for request types, errors, and responses specific to those frameworks.Available Integrations
Target Crate Notes actixoxide-auth-actixasyncwrappersoxide-auth-asyncredisoxide-auth-dbrocketoxide-auth-rocketRequires nightly rouilleoxide-auth-rouilleironoxide-auth-ironpoemoxide-auth-poemaxumoxide-auth-axum(Available in repository) How OAuth2 scopes and access control work
masterIn
oxide-auth, aScopeis a set of space-separated tokens. Scopes follow a partial ordering logic based on conjunction: a scope is considered a subset of another if all its tokens are present in the other scope.Access Control Logic
- Resource Requirement: A resource requires a specific
Scope(theresource_scope). - Grant Privileges: A user holds a
Scope(thegrant_scope). - Rule: Access is granted if the
resource_scopeis a subset of thegrant_scope(i.e.,resource_scope <= grant_scope).
Comparison Summary
Operation Meaning Logic resource_scope.allow_access(&grant_scope)Can the resource allow this grant? resource_scope <= grant_scopegrant_scope.priviledged_to(&resource_scope)Does the grant have enough privilege for the resource? resource_scope <= grant_scopeNote that if scopes contain incomparable tokens (e.g.,
A BvsA C), they are not considered subsets of each other.```rust use oxide_auth::primitives::scope::Scope; let grant_scope = "some_scope other_scope".parse::<Scope>().unwrap(); let resource_scope = "some_scope".parse::<Scope>().unwrap(); let uncomparable = "some_scope third_scope".parse::<Scope>().unwrap(); // Access granted because resource_scope is a subset of grant_scope assert!(resource_scope.allow_access(&grant_scope)); assert!(grant_scope.priviledged_to(&resource_scope)); // Access denied because tokens are incomparable assert!(!uncomparable.allow_access(&grant_scope)); ```埋- Resource Requirement: A resource requires a specific
Untitled record
masterDBRegistraris a database-backed implementation of theRegistrartrait fromoxide-auth. It manages the storage, retrieval, and validation of OAuth2 clients using aDataSource(repository).Key features:
- Client Registration: Persists
Clientobjects by encoding them with aPasswordPolicy(defaults toArgon2). - Password Policy Management: Allows customizing how client secrets are encoded using
set_password_policy. - OAuth2 Compliance: Implements
bound_redirectfor URI validation,negotiatefor pre-grant generation, andcheckfor client authentication.
To use
DBRegistrar, you must provide a connection URL, a maximum pool size, and a client prefix for your database keys.use oxide_auth::primitives::registrar::{Client, Registrar}; // Note: DBRegistrar requires a DataSource implementation (e.g., Redis via the oxide-auth-db crate) let mut registrar = DBRegistrar::new( "redis://localhost/0".to_string(), 32, "client:".to_string() ).unwrap();- Client Registration: Persists
Configure RegisteredUrl matching strategies
masterWhen registering redirect URIs, you can choose between different matching behaviors using the
RegisteredUrlenum:Exact(ExactUrl): Requires a literal, character-for-character match of the string. Useful for preventing injection of unexpected query parameters.Semantic(Url): Uses standard URL semantic matching (e.g., normalization).IgnorePortOnLocalhost(IgnoreLocalPortUrl): Matches the URL semantically but ignores the port number if the host islocalhost. This follows IETF recommendations for local development.
pub enum RegisteredUrl { Exact(ExactUrl), Semantic(Url), IgnorePortOnLocalhost(IgnoreLocalPortUrl), }