Created
March 31, 2024 21:41
-
-
Save ywegel/294f570f91c0edbbef523d3d3aee4548 to your computer and use it in GitHub Desktop.
Integrating token manager with axum
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pub type SharedTokenManager = Arc<Mutex<TokenManager>>; | |
#[tokio::main] | |
async fn main() -> anyhow::Result<()> { | |
... | |
let shared_token_manager = { | |
let manager = TokenManager::new(&config.google_application_credentials) | |
.context("Failed to create token manager")?; | |
SharedTokenManager::new(Mutex::new(manager)) | |
}; | |
let app = Router::new() | |
.layer(Extension(shared_token_manager)) | |
... | |
} | |
fun request(Extension(mut token_manager): Extension<SharedTokenManager>) { | |
let mut token_manager_guard = token_manager.lock().await; | |
let auth_token = token_manager_guard.get_token().await?; | |
// use auth_token to send fcm message | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment