mirror of
https://github.com/PluralKit/PluralKit.git
synced 2026-02-08 06:47:56 +00:00
feat(api): add internal auth
This commit is contained in:
parent
47e1c68a11
commit
0e65d9b2ee
3 changed files with 30 additions and 3 deletions
|
|
@ -58,8 +58,23 @@ pub async fn auth(State(ctx): State<ApiContext>, mut req: Request, next: Next) -
|
|||
authed_app_id = Some(1);
|
||||
}
|
||||
|
||||
// todo: fix syntax
|
||||
let internal = if req.headers().get("x-pluralkit-client-ip").is_none()
|
||||
&& let Some(auth_header) = req
|
||||
.headers()
|
||||
.get("x-pluralkit-internalauth")
|
||||
.map(|h| h.to_str().ok())
|
||||
.flatten()
|
||||
&& let Some(real_token) = libpk::config.internal_auth.clone()
|
||||
&& auth_header.as_bytes().ct_eq(real_token.as_bytes()).into()
|
||||
{
|
||||
true
|
||||
} else {
|
||||
false
|
||||
};
|
||||
|
||||
req.extensions_mut()
|
||||
.insert(AuthState::new(authed_system_id, authed_app_id));
|
||||
.insert(AuthState::new(authed_system_id, authed_app_id, internal));
|
||||
|
||||
next.run(req).await
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue