Skip to content

Commit

Permalink
Fix the filename to be more descriptive
Browse files Browse the repository at this point in the history
Fixed the filename to be more descriptive

The oauth2 file does not reflect what it actually responds to
  • Loading branch information
zeritiq committed Apr 3, 2023
1 parent 372271d commit 4c28ea8
Show file tree
Hide file tree
Showing 18 changed files with 119 additions and 65 deletions.
8 changes: 4 additions & 4 deletions aliri_actix/src/jwt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use actix_web::{
FromRequest, HttpRequest, ResponseError,
};
use aliri::{jwt, JwtRef};
use aliri_oauth2::{oauth2::HasScope, Authority, AuthorityError, ScopePolicy};
use aliri_oauth2::{scope::HasScope, Authority, AuthorityError, ScopePolicy};
use serde::Deserialize;
use thiserror::Error;

Expand Down Expand Up @@ -229,7 +229,7 @@ where
/// use aliri_actix::jwt::AllowAll;
/// use aliri_clock::UnixTime;
/// use aliri::jwt;
/// use aliri_oauth2::oauth2;
/// use aliri_oauth2::scope;
/// use serde::Deserialize;
///
/// #[derive(Clone, Debug, Deserialize)]
Expand Down Expand Up @@ -259,7 +259,7 @@ where
/// }
/// ```
#[derive(Debug)]
pub struct AllowAll<C = aliri_oauth2::oauth2::BasicClaimsWithScope>(C);
pub struct AllowAll<C = aliri_oauth2::scope::BasicClaimsWithScope>(C);

impl<C> AllowAll<C> {
/// Borrows a reference to the inner claims payload
Expand Down Expand Up @@ -301,7 +301,7 @@ mod tests {
use actix_web::{get, test, App, HttpResponse, Responder};
use aliri::{jwa, jwk, Jwk, Jwks};
use aliri_base64::Base64Url;
use aliri_oauth2::{oauth2::BasicClaimsWithScope, Scope};
use aliri_oauth2::{scope::BasicClaimsWithScope, Scope};
use color_eyre::Result;
use once_cell::sync::OnceCell;

Expand Down
6 changes: 3 additions & 3 deletions aliri_actix/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@
/// use aliri::jwt;
/// use aliri_actix::scope_policy;
/// use aliri_clock::UnixTime;
/// use aliri_oauth2::oauth2;
/// use aliri_oauth2::scope;
/// use serde::Deserialize;
/// use actix_web::{get, HttpResponse, Responder};
///
Expand Down Expand Up @@ -167,7 +167,7 @@
#[macro_export]
macro_rules! scope_policy {
($i:ident/$s:ident; $($($scope:literal),*);*) => {
scope_policy!($i/$s(::aliri_oauth2::oauth2::BasicClaimsWithScope); $($($scope),*);*);
scope_policy!($i/$s(::aliri_oauth2::scope::BasicClaimsWithScope); $($($scope),*);*);
};
($i:ident/$s:ident($claim:ty); $($($scope:literal),*);*) => {
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
Expand Down Expand Up @@ -199,7 +199,7 @@ macro_rules! scope_policy {
.or_allow(
::aliri_oauth2::Scope::empty()
$(
.and(::aliri_oauth2::oauth2::ScopeToken::from_static($scope))
.and(::aliri_oauth2::scope::ScopeToken::from_static($scope))
)*
)
)*
Expand Down
10 changes: 5 additions & 5 deletions aliri_axum/examples/auth0_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::time::Duration;
use aliri::{error::JwtVerifyError, jwa, jwt};
use aliri_axum::scope_guards;
use aliri_clock::UnixTime;
use aliri_oauth2::{oauth2, Authority};
use aliri_oauth2::{scope, Authority};
use aliri_tower::Oauth2Authorizer;
use axum::{
extract::Path,
Expand Down Expand Up @@ -133,8 +133,8 @@ pub struct CustomClaims {
exp: UnixTime,
iat: UnixTime,
azp: ClientId,
scope: oauth2::Scope,
permissions: oauth2::Scope,
scope: scope::Scope,
permissions: scope::Scope,
}

impl jwt::CoreClaims for CustomClaims {
Expand All @@ -155,8 +155,8 @@ impl jwt::CoreClaims for CustomClaims {
}
}

impl oauth2::HasScope for CustomClaims {
fn scope(&self) -> &oauth2::Scope {
impl scope::HasScope for CustomClaims {
fn scope(&self) -> &scope::Scope {
&self.scope
}
}
Expand Down
10 changes: 5 additions & 5 deletions aliri_axum/examples/auth0_token.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use aliri::{jwt, JwtRef};
use aliri_braid::braid;
use aliri_oauth2::oauth2;
use aliri_oauth2::scope;

#[tokio::main]
async fn main() -> color_eyre::Result<()> {
Expand All @@ -22,7 +22,7 @@ struct UserCode;
#[derive(serde::Serialize)]
struct DeviceFlowRequest<'a> {
client_id: &'a ClientIdRef,
scope: &'a oauth2::Scope,
scope: &'a scope::Scope,
audience: &'a jwt::AudienceRef,
}

Expand Down Expand Up @@ -61,7 +61,7 @@ struct TokenError<'a> {
struct TokenSuccess<'a> {
#[serde(borrow)]
access_token: &'a JwtRef,
scope: oauth2::Scope,
scope: scope::Scope,
expires_in: aliri_clock::DurationSecs,
}

Expand All @@ -72,8 +72,8 @@ async fn perform_device_login_flow(

let scope = scope
.into_iter()
.map(oauth2::ScopeToken::try_from)
.collect::<Result<oauth2::Scope, _>>()?;
.map(scope::ScopeToken::try_from)
.collect::<Result<scope::Scope, _>>()?;

let client = reqwest::Client::default();
let resp = client
Expand Down
8 changes: 4 additions & 4 deletions aliri_axum/examples/axum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use aliri::{jwa, jwk, jwt, Jwk, Jwks, Jwt};
use aliri_axum::scope_guards;
use aliri_base64::Base64UrlRef;
use aliri_clock::{Clock, DurationSecs, UnixTime};
use aliri_oauth2::{oauth2, scope, Authority};
use aliri_oauth2::{scope, Authority};
use aliri_tower::Oauth2Authorizer;
use axum::{
extract::Path,
Expand Down Expand Up @@ -44,7 +44,7 @@ pub struct CustomClaims {
aud: jwt::Audiences,
sub: jwt::Subject,
exp: UnixTime,
scope: oauth2::Scope,
scope: scope::Scope,
}

impl jwt::CoreClaims for CustomClaims {
Expand All @@ -65,8 +65,8 @@ impl jwt::CoreClaims for CustomClaims {
}
}

impl oauth2::HasScope for CustomClaims {
fn scope(&self) -> &oauth2::Scope {
impl scope::HasScope for CustomClaims {
fn scope(&self) -> &scope::Scope {
&self.scope
}
}
Expand Down
8 changes: 4 additions & 4 deletions aliri_axum/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
use std::{error::Error, fmt};

use aliri_oauth2::{oauth2, ScopePolicy};
use aliri_oauth2::{scope, ScopePolicy};
use axum_core::response::{IntoResponse, Response};
use http::StatusCode;

Expand All @@ -112,7 +112,7 @@ mod macros;
/// Defines a scope policy for a given endpoint guard
pub trait EndpointScopePolicy {
/// The claims structure to extract from the request extensions and return if authorized
type Claims: oauth2::HasScope;
type Claims: scope::HasScope;

/// The scope policy to be enforced when this type is used as an endpoint guard
fn scope_policy() -> &'static ScopePolicy;
Expand Down Expand Up @@ -206,7 +206,7 @@ pub struct VerboseAuthxErrors;

#[doc(hidden)]
pub mod __private {
use aliri_oauth2::oauth2;
use aliri_oauth2::scope;
pub use aliri_oauth2::ScopePolicy;
use aliri_traits::Policy;
use http::request::Parts;
Expand All @@ -219,7 +219,7 @@ pub mod __private {
policy: &'static ScopePolicy,
) -> Result<Claims, AuthFailed>
where
Claims: oauth2::HasScope + Send + Sync + 'static,
Claims: scope::HasScope + Send + Sync + 'static,
{
let claims = req
.extensions
Expand Down
18 changes: 9 additions & 9 deletions aliri_axum/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
/// use aliri::jwt;
/// use aliri_axum::scope_guard;
/// use aliri_clock::UnixTime;
/// use aliri_oauth2::oauth2;
/// use aliri_oauth2::scope;
/// use serde::Deserialize;
///
/// #[derive(Clone, Debug, Deserialize)]
Expand Down Expand Up @@ -130,13 +130,13 @@
#[macro_export]
macro_rules! scope_guard {
($vis:vis $i:ident; *) => {
$crate::scope_guard!($vis $i(::aliri_oauth2::oauth2::BasicClaimsWithScope); *);
$crate::scope_guard!($vis $i(::aliri_oauth2::scope::BasicClaimsWithScope); *);
};
($vis:vis $i:ident; $scope:literal) => {
$crate::scope_guard!($vis $i; [$scope]);
};
($vis:vis $i:ident; [$($scope:literal)||* $(,)?]) => {
$crate::scope_guard!($vis $i(::aliri_oauth2::oauth2::BasicClaimsWithScope); [$($scope)||*]);
$crate::scope_guard!($vis $i(::aliri_oauth2::scope::BasicClaimsWithScope); [$($scope)||*]);
};
($vis:vis $i:ident($claim:ty); $scope:literal) => {
$crate::scope_guard!($vis $i($claim); [$scope]);
Expand Down Expand Up @@ -275,7 +275,7 @@ macro_rules! scope_guard {
///
/// ```
/// use aliri_axum::scope_guards;
/// use aliri_oauth2::oauth2;
/// use aliri_oauth2::scope;
///
/// struct CustomClaims {
/// scope: oauth2::Scope,
Expand Down Expand Up @@ -314,7 +314,7 @@ macro_rules! scope_guards {

#[cfg(test)]
mod tests {
use aliri_oauth2::{oauth2, scope};
use aliri_oauth2::{scope};
use axum::{
extract::FromRequestParts,
http::{request::Parts, Request},
Expand All @@ -332,10 +332,10 @@ mod tests {
scope TestingAdmin = ["testing admin"];
}

struct MyClaims(oauth2::Scope);
struct MyClaims(scope::Scope);

impl oauth2::HasScope for MyClaims {
fn scope(&self) -> &oauth2::Scope {
impl scope::HasScope for MyClaims {
fn scope(&self) -> &scope::Scope {
&self.0
}
}
Expand All @@ -344,7 +344,7 @@ mod tests {
Request::new(()).into_parts().0
}

fn request_with_scope(scope: oauth2::Scope) -> Parts {
fn request_with_scope(scope: scope::Scope) -> Parts {
let mut parts = Request::new(()).into_parts().0;
parts.extensions.insert(MyClaims(scope));
parts
Expand Down
2 changes: 1 addition & 1 deletion aliri_oauth2/src/authority.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use reqwest::{
use serde::Deserialize;
use thiserror::Error;

use crate::{oauth2::HasScope, ScopePolicy};
use crate::{scope::HasScope, ScopePolicy};

/// Indicates the requester held insufficient scopes to be granted access
/// to a controlled resource
Expand Down
4 changes: 2 additions & 2 deletions aliri_oauth2/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@
)]

mod authority;
pub mod oauth2;
pub mod scope;
mod policy;

pub use authority::{Authority, AuthorityError};
pub use oauth2::Scope;
pub use scope::Scope;
pub use policy::{InsufficientScope, ScopePolicy};
22 changes: 11 additions & 11 deletions aliri_oauth2/src/oauth2.rs → aliri_oauth2/src/scope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub enum InvalidScopeToken {
}
aliri_braid::from_infallible!(InvalidScopeToken);

/// An OAuth2 scope token as defined in [RFC 6749, Section 3.3][RFC6749 3.3]
/// An OAuth2 (or OIDC) scope token as defined in [RFC 6749, Section 3.3][RFC6749 3.3]
///
/// A scope token must be composed of printable ASCII characters excluding
/// ` ` (space), `"` (double quote), and `\` (backslash).
Expand All @@ -40,7 +40,7 @@ aliri_braid::from_infallible!(InvalidScopeToken);
#[braid(
serde,
validator,
ref_doc = "A borrowed reference to an OAuth2 [`ScopeToken`]"
ref_doc = "A borrowed reference to an OAuth2 (or OIDC) [`ScopeToken`]"
)]
#[must_use]
pub struct ScopeToken(compact_str::CompactString);
Expand Down Expand Up @@ -141,7 +141,7 @@ impl From<Scope> for ScopeDto {
}
}

/// An OAuth2 Scope defining a set of access permissions
/// An OAuth2 (or OIDC) Scope defining a set of access permissions
#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)]
#[serde(try_from = "Option<ScopeDto>", into = "ScopeDto")]
#[must_use]
Expand Down Expand Up @@ -459,9 +459,9 @@ impl jwt::CoreClaims for BasicClaimsWithScope {
}
}

/// Indicates that the type has an OAuth2 scope claim
/// Indicates that the type has an OAuth2 (or OIDC) scope claim
pub trait HasScope {
/// OAuth2 scope
/// OAuth2 (or OIDC) scope
///
/// Scope claimed by the underlying token, generally in the `scope`
/// claim.
Expand Down Expand Up @@ -493,12 +493,12 @@ impl HasScope for Scope {
/// This is equivalent to the following:
///
/// ```
/// use aliri_oauth2::{oauth2, Scope};
/// use aliri_oauth2::{scope, Scope};
///
/// let scope = Scope::empty()
/// .and(oauth2::ScopeToken::from_static("users.read"))
/// .and(oauth2::ScopeToken::from_static("users.update"))
/// .and(oauth2::ScopeToken::from_static("users.list"));
/// .and(scope::ScopeToken::from_static("users.read"))
/// .and(scope::ScopeToken::from_static("users.update"))
/// .and(scope::ScopeToken::from_static("users.list"));
/// ```
///
/// # Panics
Expand Down Expand Up @@ -529,13 +529,13 @@ macro_rules! scope {
{
$crate::Scope::empty()
$(
.and($crate::oauth2::ScopeToken::from_static($token))
.and($crate::scope::ScopeToken::from_static($token))
)+
}
};
($($token:expr),+ $(,)?) => {
{
let __f = || -> Result<$crate::Scope, $crate::oauth2::InvalidScopeToken> {
let __f = || -> Result<$crate::Scope, $crate::scope::InvalidScopeToken> {
::core::result::Result::Ok(
$crate::Scope::empty()
$(
Expand Down
Loading

0 comments on commit 4c28ea8

Please sign in to comment.