Skip to content

Commit

Permalink
prog
Browse files Browse the repository at this point in the history
  • Loading branch information
aumetra committed Dec 11, 2024
1 parent 6d71b69 commit c625882
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);

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
}

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);

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

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

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

0 comments on commit c625882

Please sign in to comment.