feat(auth): add authentication protocol definitions and build configuration
- Add TokenClaims message for JWT payload structure with user id, issuer, timestamps, and scopes - Implement IssueTokenRequest/Response for creating access and refresh tokens with TTL support - Create RefreshTokenRequest/Response for token rotation functionality - Define RevokeTokenRequest/Response with support for single token or user-wide revocation - Add VerifyTokenRequest/Response for validating JWT tokens with detailed claims information - Implement signing key distribution system with GetSigningKeysRequest/Response - Create TokenService gRPC service with IssueToken, RefreshToken, RevokeToken, VerifyToken, and GetSigningKeys methods - Add build.rs configuration to compile proto files using tonic_prost_build - Include channel, channel_settings, member, and permission protocol definitions for IM services - Generate Rust code bindings through pb/core.rs and pb/im.rs modules
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
use crate::engine::packet::Packet;
|
||||
use crate::engine::session::{SessionState, SessionStore, TransportType};
|
||||
|
||||
pub async fn handle_upgrade_probe(
|
||||
store: &SessionStore,
|
||||
sid: &str,
|
||||
) -> Result<Packet, UpgradeError> {
|
||||
let session = store.get(sid).ok_or(UpgradeError::SessionNotFound)?;
|
||||
let mut session = session.write().await;
|
||||
|
||||
if session.state == SessionState::Closed {
|
||||
return Err(UpgradeError::SessionClosed);
|
||||
}
|
||||
|
||||
session.set_state(SessionState::Upgrading);
|
||||
Ok(Packet::pong("probe"))
|
||||
}
|
||||
|
||||
pub async fn handle_upgrade_complete(
|
||||
store: &SessionStore,
|
||||
sid: &str,
|
||||
new_transport: TransportType,
|
||||
) -> Result<(), UpgradeError> {
|
||||
let session = store.get(sid).ok_or(UpgradeError::SessionNotFound)?;
|
||||
let mut session = session.write().await;
|
||||
|
||||
session.set_transport(new_transport);
|
||||
session.set_state(SessionState::Open);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn send_noop_to_pending_polling(
|
||||
store: &SessionStore,
|
||||
sid: &str,
|
||||
) -> Result<(), UpgradeError> {
|
||||
let session = store.get(sid).ok_or(UpgradeError::SessionNotFound)?;
|
||||
let mut session = session.write().await;
|
||||
|
||||
session.buffer_packet(Packet::noop());
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
pub enum UpgradeError {
|
||||
#[error("session not found")]
|
||||
SessionNotFound,
|
||||
#[error("session closed")]
|
||||
SessionClosed,
|
||||
#[error("invalid state for upgrade")]
|
||||
InvalidState,
|
||||
}
|
||||
Reference in New Issue
Block a user