Skip to content

Commit

Permalink
removing some todos
Browse files Browse the repository at this point in the history
  • Loading branch information
bruno-ortiz committed Jan 19, 2024
1 parent 79e8b1a commit 67ab1e1
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 14 deletions.
1 change: 0 additions & 1 deletion core/src/authorisation_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ impl AuthorisationRequest {
));
}
}
//TODO: claims should come from the request or the request_object
let claims = match parse_claims(configuration, &this) {
Ok(c) => c,
Err(err) => return Err((err, this)),
Expand Down
2 changes: 1 addition & 1 deletion core/src/configuration/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ pub struct OpenIDProviderConfiguration {
interaction_base_url: Box<dyn Fn(&Self) -> &Url + Send + Sync>,
#[builder(setter(skip))]
interaction_url_resolver: InteractionUrlResolver,
subject_types_supported: Vec<SubjectType>, //TODO: create subject type resolvers
subject_types_supported: Vec<SubjectType>, //TODO: check subject type on dynamic client registration
#[getset(skip)]
#[get_copy = "pub"]
auth_max_age: u64,
Expand Down
2 changes: 0 additions & 2 deletions core/src/configuration/ttl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ use time::Duration;

use crate::models::client::{AuthenticatedClient, ClientInformation};

//todo: allow generic params to be passed to this function
// this can allow the duration to be parameterized with a consent duration for example;
type TTLResolver = Box<dyn Fn(&ClientInformation) -> Duration + Send + Sync>;
type AsyncTTLResolver = Box<dyn Fn(&AuthenticatedClient) -> BoxFuture<Duration> + Send + Sync>;

Expand Down
12 changes: 8 additions & 4 deletions core/src/grant_type/refresh_token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,14 @@ impl GrantTypeResolver for RefreshTokenGrant {
async fn execute(self, client: AuthenticatedClient) -> Result<TokenResponse, OpenIdError> {
let configuration = OpenIDProviderConfiguration::instance();
let clock = configuration.clock_provider();
let grant = self;
let grant_type = self;

let mut refresh_token = configuration
.adapters()
.refresh()
.find(&grant.refresh_token)
.find(&grant_type.refresh_token)
.await
.ok_or_else(|| OpenIdError::invalid_grant("Refresh token not found"))?
.validate()?;
.ok_or_else(|| OpenIdError::invalid_grant("Refresh token not found"))?;

let grant = Grant::find(refresh_token.grant_id)
.await
Expand All @@ -42,6 +41,11 @@ impl GrantTypeResolver for RefreshTokenGrant {
"Client mismatch for refresh token",
));
}
if let Err(err) = refresh_token.validate() {
// invalidate entire token chain
grant.consume().await?;
return Err(err);
}

let context = RTContext {
config: configuration,
Expand Down
5 changes: 2 additions & 3 deletions core/src/models/refresh_token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,14 @@ impl RefreshToken {
.map_err(OpenIdError::server_error)
}

pub fn validate(self) -> Result<Self, OpenIdError> {
pub fn validate(&self) -> Result<(), OpenIdError> {
if self.status == Status::Consumed {
//TODO: invalidate entire token chain
return Err(OpenIdError::invalid_grant("Refresh token already used"));
}
if self.is_expired() {
return Err(OpenIdError::invalid_grant("Refresh token is expired"));
}
Ok(self)
Ok(())
}

pub fn total_lifetime(&self) -> Duration {
Expand Down
6 changes: 4 additions & 2 deletions core/src/pairwise.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use thiserror::Error;
use url::{Host, Url};

use oidc_types::client::ClientID;
use oidc_types::password_hasher::PasswordHasher;
use oidc_types::password_hasher::{HashingError, PasswordHasher};
use oidc_types::subject::Subject;

use crate::configuration::OpenIDProviderConfiguration;
Expand All @@ -19,6 +19,8 @@ pub enum PairwiseError {
InvalidDomain(Url),
#[error("Host not found for uri: {}", .0)]
HostNotFound(Url),
#[error("Error calculating hash for pairwise sub: {}", .0)]
Hashing(#[from] HashingError),
}

#[derive(Clone)]
Expand Down Expand Up @@ -58,7 +60,7 @@ impl PairwiseResolver {
let hasher = config.secret_hasher();
let sector_identifier = select_sector_identifier(client)?;
let sub = [sector_identifier.as_bytes(), subject.as_ref()].concat();
let hash = hasher.hash(&sub).expect("Fix later");
let hash = hasher.hash(&sub)?;
Ok(PairwiseSubject(Subject::new(hash)))
})
}
Expand Down
2 changes: 1 addition & 1 deletion types/src/password_hasher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use thiserror::Error;

const SALT_LEN: usize = 16;

#[derive(Debug, Error)]
#[derive(Debug, Error, Clone)]
pub enum HashingError {
#[error("Error decoding hash: {}", .0)]
DecodeError(#[from] DecodeError),
Expand Down

0 comments on commit 67ab1e1

Please sign in to comment.