Add /openid/token route

This commit is contained in:
2022-04-12 20:40:44 +02:00
parent 97203a955d
commit d69b44528e
8 changed files with 188 additions and 16 deletions

View File

@ -17,10 +17,13 @@ pub struct Session {
pub redirect_uri: String,
pub authorization_code: String,
pub code_expire_on: u64,
pub authorization_code_expire_at: u64,
pub authorization_code_used: bool,
pub token: String,
pub token_expire_at: u64,
pub access_token: String,
pub access_token_expire_at: u64,
pub refresh_token: String,
pub refresh_token_expire_at: u64,
pub nonce: Option<String>,
pub code_challenge: Option<(String, String)>,
@ -28,7 +31,8 @@ pub struct Session {
impl Session {
pub fn is_expired(&self) -> bool {
self.code_expire_on < time() && self.token_expire_at < time()
self.authorization_code_expire_at < time() && self.access_token_expire_at < time()
&& self.refresh_token_expire_at < time()
}
}
@ -36,6 +40,14 @@ impl Session {
#[rtype(result = "()")]
pub struct PushNewSession(pub Session);
#[derive(Message)]
#[rtype(result = "Option<Session>")]
pub struct FindSessionByAuthorizationCode(pub String);
#[derive(Message)]
#[rtype(result = "()")]
pub struct MarkAuthorizationCodeUsed(pub String);
#[derive(Default)]
pub struct OpenIDSessionsActor {
session: Vec<Session>,
@ -65,4 +77,27 @@ impl Handler<PushNewSession> for OpenIDSessionsActor {
fn handle(&mut self, msg: PushNewSession, _ctx: &mut Self::Context) -> Self::Result {
self.session.push(msg.0)
}
}
impl Handler<FindSessionByAuthorizationCode> for OpenIDSessionsActor {
type Result = Option<Session>;
fn handle(&mut self, msg: FindSessionByAuthorizationCode, _ctx: &mut Self::Context) -> Self::Result {
self.session
.iter()
.find(|f| f.authorization_code.eq(&msg.0))
.cloned()
}
}
impl Handler<MarkAuthorizationCodeUsed> for OpenIDSessionsActor {
type Result = ();
fn handle(&mut self, msg: MarkAuthorizationCodeUsed, _ctx: &mut Self::Context) -> Self::Result {
if let Some(r) = self.session
.iter_mut()
.find(|f| f.authorization_code.eq(&msg.0)) {
r.authorization_code_used = true;
}
}
}