pub struct SasTokenGenerator { /* private fields */ }Expand description
Generator for Azure Service Bus Shared Access Signature (SAS) tokens.
Creates time-limited authentication tokens using HMAC-SHA256 signing with shared access keys. SAS tokens provide a secure way to grant limited access to Service Bus resources without sharing the primary keys.
§Security Notes
- Generated tokens have configurable expiration times
- Uses HMAC-SHA256 for cryptographic signing
- Keys are base64 decoded before use in signing
- Tokens include URL-encoded resource URIs for security
§Examples
use quetty_server::auth::SasTokenGenerator;
let generator = SasTokenGenerator::new("my-namespace".to_string());
let token = generator.generate_sas_token(
"RootManageSharedAccessKey",
"base64_encoded_key",
24 // 24 hours
)?;Implementations§
Source§impl SasTokenGenerator
impl SasTokenGenerator
Sourcepub fn generate_sas_token(
&self,
key_name: &str,
key: &str,
duration_hours: i64,
) -> Result<String, ServiceBusError>
pub fn generate_sas_token( &self, key_name: &str, key: &str, duration_hours: i64, ) -> Result<String, ServiceBusError>
Generates a SAS token for Service Bus authentication.
Creates a time-limited Shared Access Signature token using HMAC-SHA256 signing with the provided shared access key. The token grants access to the entire Service Bus namespace.
§Arguments
key_name- The name of the shared access key policykey- The base64-encoded shared access keyduration_hours- Token validity period in hours
§Returns
A complete SAS token string ready for use in Service Bus operations
§Errors
Returns ServiceBusError::AuthenticationError if:
- The key cannot be base64 decoded
- HMAC generation fails
- Token signing fails
§Examples
use quetty_server::auth::SasTokenGenerator;
let generator = SasTokenGenerator::new("namespace".to_string());
let token = generator.generate_sas_token(
"RootManageSharedAccessKey",
"base64_encoded_key_here",
24 // Valid for 24 hours
)?;Sourcepub fn create_connection_string_from_sas(&self, sas_token: &str) -> String
pub fn create_connection_string_from_sas(&self, sas_token: &str) -> String
Creates a Service Bus connection string from a SAS token.
Combines the namespace endpoint with the SAS token to create a complete connection string that can be used for Service Bus operations.
§Arguments
sas_token- A valid SAS token (typically from [generate_sas_token])
§Returns
A complete Service Bus connection string
§Examples
use quetty_server::auth::SasTokenGenerator;
let generator = SasTokenGenerator::new("namespace".to_string());
let token = generator.generate_sas_token("key_name", "key", 24)?;
let connection_string = generator.create_connection_string_from_sas(&token);Trait Implementations§
Source§impl Clone for SasTokenGenerator
impl Clone for SasTokenGenerator
Source§fn clone(&self) -> SasTokenGenerator
fn clone(&self) -> SasTokenGenerator
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more