validateToken method

  1. @override
Future<AuthResult> validateToken(
  1. String token, {
  2. List<String>? requiredScopes,
})
override

Validate a bearer token

Implementation

@override
Future<AuthResult> validateToken(String token, {List<String>? requiredScopes}) async {
  final keyInfo = _validApiKeys[token];

  if (keyInfo == null) {
    return const AuthResult.failure(error: 'Invalid API key');
  }

  // Check if key is expired
  final exp = keyInfo['exp'] as int?;
  if (exp != null && DateTime.now().millisecondsSinceEpoch > exp * 1000) {
    return const AuthResult.failure(error: 'API key expired');
  }

  return AuthResult.success(
    userInfo: keyInfo,
    validatedScopes: (keyInfo['scopes'] as List<dynamic>?)?.cast<String>() ?? const [],
  );
}