auth_token_generator 1.0.0 auth_token_generator: ^1.0.0 copied to clipboard
A Dart package for generating and validating bearer tokens using HMAC-SHA256 encryption.
example/auth_token_generator_example.dart
import 'package:auth_token_generator/auth_token_generator.dart';
/// Main function to demonstrate token generation and user ID extraction.
void main() {
// Generate a Bearer token with a user ID
final secretKey = 'my_secret_key';
final userId = 'user123';
final token = AuthTokenGenerator.generateBearerToken(secretKey, userId: userId);
print('Generated token: $token');
// Extract the user ID from the generated token
final extractedUserId = AuthTokenGenerator.getUserIdFromBearerToken(secretKey, token);
if (extractedUserId != null) {
print('Extracted user ID: $extractedUserId');
} else {
print('Invalid token or signature.');
}
}