46 lines
1.4 KiB
Dart
46 lines
1.4 KiB
Dart
|
|
/// 认证域模型(P3 计划 Task 2)。
|
|||
|
|
///
|
|||
|
|
/// 契约来源:`packages/contracts/openapi.yaml` tag `auth`。
|
|||
|
|
library;
|
|||
|
|
|
|||
|
|
/// 密码登录响应。
|
|||
|
|
///
|
|||
|
|
/// 契约 `components.schemas.LoginResponse`(operationId `loginWithPassword`
|
|||
|
|
/// ,POST /auth/password → 200)。
|
|||
|
|
class LoginResponse {
|
|||
|
|
const LoginResponse({required this.sessionToken, required this.expiresAt});
|
|||
|
|
|
|||
|
|
factory LoginResponse.fromJson(Map<String, dynamic> json) => LoginResponse(
|
|||
|
|
sessionToken: json['sessionToken'] as String,
|
|||
|
|
expiresAt: DateTime.parse(json['expiresAt'] as String),
|
|||
|
|
);
|
|||
|
|
|
|||
|
|
/// 会话令牌(Bearer)。
|
|||
|
|
final String sessionToken;
|
|||
|
|
|
|||
|
|
/// 会话过期时间(date-time)。
|
|||
|
|
final DateTime expiresAt;
|
|||
|
|
|
|||
|
|
Map<String, dynamic> toJson() => {
|
|||
|
|
'sessionToken': sessionToken,
|
|||
|
|
'expiresAt': expiresAt.toUtc().toIso8601String(),
|
|||
|
|
};
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// 会话滑动续期响应。
|
|||
|
|
///
|
|||
|
|
/// 契约 `components.schemas.RefreshResponse`(operationId `refreshSession`
|
|||
|
|
/// ,POST /auth/refresh → 200):令牌不变,仅返回新的过期时间。
|
|||
|
|
class RefreshResponse {
|
|||
|
|
const RefreshResponse({required this.expiresAt});
|
|||
|
|
|
|||
|
|
factory RefreshResponse.fromJson(Map<String, dynamic> json) =>
|
|||
|
|
RefreshResponse(expiresAt: DateTime.parse(json['expiresAt'] as String));
|
|||
|
|
|
|||
|
|
/// 续期后的过期时间(date-time)。
|
|||
|
|
final DateTime expiresAt;
|
|||
|
|
|
|||
|
|
Map<String, dynamic> toJson() =>
|
|||
|
|
{'expiresAt': expiresAt.toUtc().toIso8601String()};
|
|||
|
|
}
|