mirror of
https://forgejo.ellis.link/continuwuation/continuwuity.git
synced 2026-11-15 13:16:56 +00:00
feat: Add admin command to issue access tokens
This commit is contained in:
1 parent
4cf743883a
commit
9a3496ae70
12 files changed
+79
-58
No files matched your search
+14
-14
@@ -547,7 +547,7 @@ impl Service {
|
||||
.iter()
|
||||
.find_map(|scope| {
|
||||
if let Scope::Device(device_id) = scope {
|
||||
Some(device_id)
|
||||
Some(device_id.to_owned())
|
||||
} else {
|
||||
None
|
||||
}
|
||||
@@ -557,7 +557,7 @@ impl Service {
|
||||
if self
|
||||
.services
|
||||
.users
|
||||
.get_device_metadata(&authorizing_user, device_id)
|
||||
.get_device_metadata(&authorizing_user, &device_id)
|
||||
.await
|
||||
.is_ok()
|
||||
{
|
||||
@@ -567,11 +567,11 @@ impl Service {
|
||||
));
|
||||
}
|
||||
|
||||
self.services
|
||||
let device_id = self.services
|
||||
.users
|
||||
.create_device(
|
||||
&authorizing_user,
|
||||
device_id,
|
||||
Some(device_id),
|
||||
Some(access_token.clone()),
|
||||
client_name,
|
||||
None,
|
||||
@@ -581,8 +581,16 @@ impl Service {
|
||||
// failure during authentication, which should(?) be impossible(?)
|
||||
.expect("failed to create device");
|
||||
|
||||
info!(
|
||||
?client_id,
|
||||
?authorizing_user,
|
||||
?device_id,
|
||||
?requested_scopes,
|
||||
"Created new oauth session"
|
||||
);
|
||||
|
||||
self.db.userdeviceid_oauthsessioninfo.put(
|
||||
(&authorizing_user, device_id),
|
||||
(&authorizing_user, &device_id),
|
||||
Json(SessionInfo {
|
||||
client_id: client_id.clone(),
|
||||
current_refresh_token: refresh_token.clone(),
|
||||
@@ -595,18 +603,10 @@ impl Service {
|
||||
Json(RefreshTokenInfo {
|
||||
client_id: client_id.clone(),
|
||||
user_id: authorizing_user.clone(),
|
||||
device_id: device_id.to_owned(),
|
||||
device_id,
|
||||
}),
|
||||
);
|
||||
|
||||
info!(
|
||||
?client_id,
|
||||
?authorizing_user,
|
||||
?device_id,
|
||||
?requested_scopes,
|
||||
"Created new oauth session"
|
||||
);
|
||||
|
||||
Ok(TokenResponse {
|
||||
access_token: access_token.into_token(),
|
||||
token_type: TokenType::Bearer,
|
||||
|
||||
@@ -40,7 +40,7 @@ impl super::Service {
|
||||
|
||||
self.create_device(
|
||||
user_id,
|
||||
&request.device_id,
|
||||
Some(request.device_id.clone()),
|
||||
None,
|
||||
request.initial_device_display_name.clone(),
|
||||
None,
|
||||
|
||||
@@ -42,32 +42,39 @@ impl DeviceToken {
|
||||
impl super::Service {
|
||||
/// Adds a new device to a user.
|
||||
///
|
||||
/// If no `device_id` is provided, a random one will be generated.
|
||||
///
|
||||
/// If no `token` is provided, the device will not be able to be logged
|
||||
/// into.
|
||||
pub async fn create_device(
|
||||
&self,
|
||||
user_id: &UserId,
|
||||
device_id: &DeviceId,
|
||||
device_id: Option<OwnedDeviceId>,
|
||||
token: Option<DeviceToken>,
|
||||
initial_device_display_name: Option<String>,
|
||||
client_ip: Option<String>,
|
||||
) -> Result<()> {
|
||||
) -> Result<OwnedDeviceId> {
|
||||
const DEVICE_ID_LENGTH: usize = 10;
|
||||
|
||||
self.status(user_id).await.ensure_active()?;
|
||||
|
||||
let key = (user_id, device_id);
|
||||
let mut device = Device::new(device_id.into());
|
||||
let device_id =
|
||||
device_id.unwrap_or_else(|| utils::random_string(DEVICE_ID_LENGTH).into());
|
||||
|
||||
let mut device = Device::new(device_id.clone());
|
||||
device.display_name = initial_device_display_name;
|
||||
device.last_seen_ip = client_ip;
|
||||
device.last_seen_ts = Some(MilliSecondsSinceUnixEpoch::now());
|
||||
|
||||
let key = (user_id, &device_id);
|
||||
increment(&self.db.userid_devicelistversion, user_id.as_bytes());
|
||||
self.db.userdeviceid_metadata.put(key, Json(device));
|
||||
|
||||
if let Some(token) = token {
|
||||
self.set_token(user_id, device_id, token).await?;
|
||||
self.set_token(user_id, &device_id, token).await?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
Ok(device_id)
|
||||
}
|
||||
|
||||
/// Removes a device from a user.
|
||||
|
||||
Reference in new issue
Block a user