Upstream commit: 474dd0229cb20cf513036619781ed97bd8073c3f Enterprise-only files removed or emptied: 63 Enterprise-only snippets removed: 117 in 50 files Dangling module declarations removed: 5 Cargo edits turning enterprise off: 14 Verification: clean Enterprise feature gates left for rebuilt features: 19 in 18 files Produced by tools/fork/strip.py. The full report is in docs/fork/strip-reports/ on main.
82 lines
2.3 KiB
Rust
82 lines
2.3 KiB
Rust
/*
|
|
* SPDX-FileCopyrightText: 2020 Stalwart Labs LLC <[email protected]>
|
|
*
|
|
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-SEL
|
|
*/
|
|
|
|
use crate::{Server, auth::AccessToken};
|
|
use serde::{Deserialize, Serialize};
|
|
use trc::{AddContext, AuthEvent, EventType};
|
|
|
|
#[derive(Debug, Default, Clone, Eq, PartialEq, Deserialize, Serialize)]
|
|
pub struct OAuthIntrospect {
|
|
#[serde(default)]
|
|
pub active: bool,
|
|
|
|
#[serde(default)]
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
pub scope: Option<String>,
|
|
|
|
#[serde(default)]
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
pub client_id: Option<String>,
|
|
|
|
#[serde(default)]
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
pub username: Option<String>,
|
|
|
|
#[serde(default)]
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
pub token_type: Option<String>,
|
|
|
|
#[serde(default)]
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
pub exp: Option<i64>,
|
|
|
|
#[serde(default)]
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
pub iat: Option<i64>,
|
|
|
|
#[serde(default)]
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
pub nbf: Option<i64>,
|
|
|
|
#[serde(default)]
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
pub sub: Option<String>,
|
|
}
|
|
|
|
impl Server {
|
|
pub async fn introspect_access_token(
|
|
&self,
|
|
token: &str,
|
|
access_token: &AccessToken,
|
|
) -> trc::Result<OAuthIntrospect> {
|
|
match self.validate_access_token(None, token).await {
|
|
Ok(token_info) => Ok(OAuthIntrospect {
|
|
active: true,
|
|
username: self
|
|
.account(access_token.account_id())
|
|
.await
|
|
.caused_by(trc::location!())?
|
|
.name()
|
|
.to_string()
|
|
.into(),
|
|
token_type: Some("bearer".into()),
|
|
exp: Some(token_info.expiry as i64),
|
|
iat: Some(token_info.issued_at as i64),
|
|
..Default::default()
|
|
}),
|
|
Err(err)
|
|
if matches!(
|
|
err.event_type(),
|
|
EventType::Auth(AuthEvent::Error) | EventType::Auth(AuthEvent::TokenExpired)
|
|
) =>
|
|
{
|
|
Ok(OAuthIntrospect::default())
|
|
}
|
|
Err(err) => Err(err),
|
|
}
|
|
}
|
|
}
|