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,41 @@
|
||||
pub mod memory;
|
||||
pub mod redis;
|
||||
|
||||
use async_trait::async_trait;
|
||||
use thiserror::Error;
|
||||
|
||||
#[derive(Error, Debug)]
|
||||
pub enum SessionError {
|
||||
#[error("Redis error: {0}")]
|
||||
Redis(String),
|
||||
#[error("Session not found: {0}")]
|
||||
NotFound(String),
|
||||
#[error("Serialization error: {0}")]
|
||||
Serialization(String),
|
||||
#[error("Session expired: {0}")]
|
||||
Expired(String),
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
||||
pub struct SessionInfo {
|
||||
pub sid: String,
|
||||
pub transport: String,
|
||||
pub state: String,
|
||||
pub server_id: String,
|
||||
pub created_at: u64,
|
||||
pub last_ping: u64,
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
pub trait SessionStoreTrait: Send + Sync + 'static {
|
||||
async fn create(&self, sid: &str, transport: &str, server_id: &str) -> Result<(), SessionError>;
|
||||
async fn get(&self, sid: &str) -> Result<Option<SessionInfo>, SessionError>;
|
||||
async fn set_state(&self, sid: &str, state: &str) -> Result<(), SessionError>;
|
||||
async fn set_transport(&self, sid: &str, transport: &str) -> Result<(), SessionError>;
|
||||
async fn update_ping(&self, sid: &str) -> Result<(), SessionError>;
|
||||
async fn remove(&self, sid: &str) -> Result<(), SessionError>;
|
||||
async fn exists(&self, sid: &str) -> Result<bool, SessionError>;
|
||||
}
|
||||
|
||||
pub use memory::InMemorySessionStore;
|
||||
pub use redis::RedisSessionStore;
|
||||
Reference in New Issue
Block a user