Skip to content

Commit

Permalink
prog
Browse files Browse the repository at this point in the history
  • Loading branch information
aumetra committed Dec 12, 2024
1 parent d9e2919 commit adb0b75
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions lib/komainu/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ sonic-rs.workspace = true
strum.workspace = true
thiserror.workspace = true
tracing.workspace = true
url.workspace = true

[dev-dependencies]
serde_test.workspace = true
Expand Down
Empty file added lib/komainu/src/authorize.rs
Empty file.
19 changes: 13 additions & 6 deletions lib/komainu/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use strum::AsRefStr;
pub use self::error::{Error, Result};
pub use self::params::ParamStorage;

mod authorize;
mod error;
mod params;

Expand Down Expand Up @@ -121,7 +122,6 @@ where
let state = query.get("state").map(|state| &**state);

Check warning on line 122 in lib/komainu/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

lib/komainu/src/lib.rs#L120-L122

Added lines #L120 - L122 were not covered by tests

let client = self.client_extractor.extract(client_id, None).await?;

if client.redirect_uri != *redirect_uri {
debug!(?client_id, "redirect uri doesn't match");
return Err(Error::Unauthorized);
Expand Down Expand Up @@ -168,17 +168,24 @@ where
}

Check warning on line 168 in lib/komainu/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

lib/komainu/src/lib.rs#L166-L168

Added lines #L166 - L168 were not covered by tests

pub async fn accept(self, user_id: AI::UserId, scopes: &[&str]) -> http::Response<()> {
// TODO: Call an issuer to issue an access token for a particular user
// Construct the callback url
// Construct a redirect HTTP response UwU

let code = self
.auth_issuer
.issue_code(user_id, self.client.client_id, scopes)
.await
.unwrap();

todo!();
let mut url = url::Url::parse(&self.client.redirect_uri).unwrap();
url.query_pairs_mut().append_pair("code", &code);

Check warning on line 178 in lib/komainu/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

lib/komainu/src/lib.rs#L170-L178

Added lines #L170 - L178 were not covered by tests

if let Some(state) = self.state {
url.query_pairs_mut().append_pair("state", state);
}

Check warning on line 182 in lib/komainu/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

lib/komainu/src/lib.rs#L180-L182

Added lines #L180 - L182 were not covered by tests

http::Response::builder()
.header(http::header::LOCATION, url.as_str())
.status(http::StatusCode::FOUND)
.body(())
.unwrap()
}

Check warning on line 189 in lib/komainu/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

lib/komainu/src/lib.rs#L184-L189

Added lines #L184 - L189 were not covered by tests

pub async fn deny(self) -> http::Response<()> {
Expand Down

0 comments on commit adb0b75

Please sign in to comment.