Content-Length: 362953 | pFad | https://github.com/sebadob/rauthy/commit/e8077ce2f6c6c21d0e83ba531efe2bf5ef1c6d84

46 Merge pull request #382 from sebadob/client-feat-qr · sebadob/rauthy@e8077ce · GitHub
Skip to content

Commit

Permalink
Merge pull request #382 from sebadob/client-feat-qr
Browse files Browse the repository at this point in the history
feat: `DeviceCode` verification uri -> qrcode
  • Loading branch information
sebadob authored Apr 29, 2024
2 parents 8d028bf + 50912b2 commit e8077ce
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 9 deletions.
4 changes: 3 additions & 1 deletion rauthy-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ axum = [
"dep:elliptic-curve",
]
device-code = []
qrcode = ["device-code", "dep:qrcode"]

[dependencies]
# common
Expand Down Expand Up @@ -53,10 +54,11 @@ axum = { version = "0.7", optional = true, features = [] }
axum-extra = { version = "0.9", optional = true, features = ["cookie", "typed-header"] }

# device-code
qrcode = { version = "0.14.0", optional = true }

# make minimal versions happy
elliptic-curve = { version = "0.13.8", optional = true }

[dev-dependencies]
pretty_assertions = "1"
rstest = "0.19"
rstest = "0.19"
9 changes: 1 addition & 8 deletions rauthy-client/examples/device-code/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,5 @@ authors = ["Sebastian Dobe <sebastiandobe@mailbox.org>"]
license = "Apache-2.0"

[dependencies]
#anyhow = "1.0.75"
#axum = { version = "0.7.1", features = ["http2"] }
#axum-extra = { version = "0.9.0", features = ["cookie"] }
dotenvy = "0.15.7"
tokio = { version = "1.34.0", features = ["full"] }
#tracing = "0.1.40"
#tracing-subscriber = { version = "0.3.18", features = ["tracing"] }

rauthy-client = { path = "../..", features = ["device-code"] }
rauthy-client = { path = "../..", features = ["device-code", "qrcode"] }
8 changes: 8 additions & 0 deletions rauthy-client/examples/device-code/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ async fn main() -> Result<(), RauthyError> {
device_code.verification_uri_complete.as_ref().unwrap()
);

// with the `qrcode` feature endabled, we can render the
// verification_uri_complete into one
let qr = device_code.qr_string()?;
println!("\n{}", qr);

// we can get a QR as SVG as well, but this example can't display it.
// let qr = device_code.qr_svg()?;

let ts = device_code.wait_for_token().await?;
println!("\nTokenSet on accept:\n{:?}", ts);

Expand Down
38 changes: 38 additions & 0 deletions rauthy-client/src/device_code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,4 +256,42 @@ impl DeviceCode {
}
}
}

#[cfg(feature = "qrcode")]
fn qr(&self) -> Result<qrcode::QrCode, RauthyError> {
if let Some(uri) = &self.verification_uri_complete {
Ok(qrcode::QrCode::new(uri)?)
} else {
Err(RauthyError::Provider(Cow::from(
"did not receive a `verification_uri_complete`",
)))
}
}

#[cfg(feature = "qrcode")]
pub fn qr_string(&self) -> Result<String, RauthyError> {
use qrcode::render::unicode;

let code = self.qr()?;
let image = code
.render::<unicode::Dense1x2>()
.dark_color(unicode::Dense1x2::Light)
.light_color(unicode::Dense1x2::Dark)
.build();
Ok(image)
}

#[cfg(feature = "qrcode")]
pub fn qr_svg(&self) -> Result<String, RauthyError> {
use qrcode::render::svg;

let code = self.qr()?;
let image = code
.render()
.min_dimensions(200, 200)
.dark_color(svg::Color("#000000"))
.light_color(svg::Color("#ffffff"))
.build();
Ok(image)
}
}
7 changes: 7 additions & 0 deletions rauthy-client/src/rauthy_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,10 @@ impl From<serde_json::Error> for RauthyError {
Self::Serde(value.to_string())
}
}

#[cfg(feature = "qrcode")]
impl From<qrcode::types::QrError> for RauthyError {
fn from(value: qrcode::types::QrError) -> Self {
Self::Internal(Cow::from(value.to_string()))
}
}

0 comments on commit e8077ce

Please sign in to comment.








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: https://github.com/sebadob/rauthy/commit/e8077ce2f6c6c21d0e83ba531efe2bf5ef1c6d84

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy