Skip to content

Commit

Permalink
lib: refactor to blocking request that fetches certs on lazy during r…
Browse files Browse the repository at this point in the history
…untime
  • Loading branch information
ernestas-poskus committed Sep 6, 2023
1 parent a9c716f commit 420a577
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 67 deletions.
18 changes: 4 additions & 14 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
[package]
name = "oauth-certs"
version = "0.1.0"
version = "0.2.0"
edition = "2021"
build = "build.rs"
description = """
The project fetches oauth certificates from providers during build time and stores them as lazy structures for retrieval.
"""
Expand All @@ -18,16 +17,7 @@ jsonwebtoken = { version = "8", default-features = false }
serde_json = "1"
once_cell = "1"

[build-dependencies]
serde_json = "1"
jsonwebtoken = { version = "8", default-features = false }

[build-dependencies.tokio]
version = "1"
default-features = false
features = ["rt-multi-thread", "macros"]

[build-dependencies.reqwest]
version = "0.11.18"
[dependencies.reqwest]
version = "0.11"
default-features = false
features = ["rustls-tls", "gzip", "json"]
features = ["rustls-tls", "gzip", "json", "blocking"]
49 changes: 0 additions & 49 deletions build.rs

This file was deleted.

15 changes: 11 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,16 @@ pub mod google {
use jsonwebtoken::jwk::JwkSet;
use once_cell::sync::Lazy;

include!(concat!(env!("OUT_DIR"), "/google-certs.rs"));
fn retrieve() -> Result<JwkSet, reqwest::Error> {
reqwest::blocking::Client::new()
.get("https://www.googleapis.com/oauth2/v3/certs")
.send()?
.json()
}

/// Google oauth certificates"
pub static OAUTH_CERTS: Lazy<JwkSet> =
Lazy::new(|| retrieve().expect("Failed to retrieve Google OAuth certificates"));
}

#[cfg(test)]
Expand All @@ -52,8 +61,6 @@ mod tests {

#[test]
fn test_google_oauth_certs() {
assert!(google::OAUTH_CERTS
.find("911e39e27928ae9f1e9d1e21646de92d19351b44")
.is_some());
assert!(!google::OAUTH_CERTS.keys.is_empty());
}
}

0 comments on commit 420a577

Please sign in to comment.