-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
160 additions
and
83 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
//! # poser | ||
//! | ||
//! poser is a simple, opinionated authentication provider for nginx | ||
//! | ||
//! ## About | ||
//! | ||
//! poser authenticates with Google using OpenID Connect and then uses the | ||
//! Google Workspace Admin SDK to determine what groups a user is a part of. | ||
//! Basic information about the user and what groups they are a part of is | ||
//! returned to nginx in a [Paseto v4] token, which is then passed to the | ||
//! application. | ||
//! | ||
//! [Paseto v4]: https://github.com/paseto-standard/paseto-spec | ||
pub mod config; | ||
pub mod error; | ||
pub mod oidc; | ||
mod routes; | ||
pub mod shutdown; | ||
pub mod token; | ||
|
||
pub use routes::routes; | ||
|
||
use std::sync::Arc; | ||
|
||
#[derive(Debug, Clone)] | ||
pub struct ServerState { | ||
pub config: crate::config::Config, | ||
pub db: Arc<tokio_postgres::Client>, | ||
pub oidc: openidconnect::core::CoreClient, | ||
|
||
// Signals back to the main thread when dropped | ||
pub shutdown: crate::shutdown::Receiver, | ||
} |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
use tokio::sync::{mpsc, watch}; | ||
|
||
#[derive(Debug)] | ||
pub struct Sender { | ||
notify: watch::Sender<()>, | ||
process_tx: mpsc::Sender<()>, | ||
process_rx: mpsc::Receiver<()>, | ||
} | ||
|
||
impl Sender { | ||
pub fn new() -> Self { | ||
let (notify, _) = watch::channel(()); | ||
let (process_tx, process_rx) = mpsc::channel(1); | ||
|
||
Self { | ||
notify, | ||
process_tx, | ||
process_rx, | ||
} | ||
} | ||
|
||
pub fn subscribe(&self) -> Receiver { | ||
Receiver { | ||
notify: self.notify.subscribe(), | ||
_handle: self.process_tx.clone(), | ||
} | ||
} | ||
|
||
pub async fn shutdown(mut self) { | ||
let _ = self.notify.send(()); | ||
|
||
drop(self.process_tx); | ||
let _ = self.process_rx.recv().await; | ||
} | ||
} | ||
|
||
impl Default for Sender { | ||
fn default() -> Self { | ||
Self::new() | ||
} | ||
} | ||
|
||
#[derive(Clone, Debug)] | ||
pub struct Receiver { | ||
notify: watch::Receiver<()>, | ||
_handle: mpsc::Sender<()>, | ||
} | ||
|
||
impl Receiver { | ||
pub async fn recv(&mut self) { | ||
let _ = self.notify.changed().await; | ||
} | ||
} |