add auth
This commit is contained in:
95
lib/core/models/frappe_session_model.dart
Normal file
95
lib/core/models/frappe_session_model.dart
Normal file
@@ -0,0 +1,95 @@
|
||||
/// Frappe Session Model
|
||||
///
|
||||
/// Data model for Frappe API session response.
|
||||
/// Used for public API authentication to access blog content.
|
||||
library;
|
||||
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
part 'frappe_session_model.g.dart';
|
||||
|
||||
/// Frappe Session Data
|
||||
///
|
||||
/// Contains session credentials from Frappe API.
|
||||
@JsonSerializable()
|
||||
class FrappeSessionData {
|
||||
/// Session ID
|
||||
final String sid;
|
||||
|
||||
/// CSRF Token
|
||||
@JsonKey(name: 'csrf_token')
|
||||
final String csrfToken;
|
||||
|
||||
const FrappeSessionData({
|
||||
required this.sid,
|
||||
required this.csrfToken,
|
||||
});
|
||||
|
||||
factory FrappeSessionData.fromJson(Map<String, dynamic> json) =>
|
||||
_$FrappeSessionDataFromJson(json);
|
||||
|
||||
Map<String, dynamic> toJson() => _$FrappeSessionDataToJson(this);
|
||||
}
|
||||
|
||||
/// Frappe Session Message Wrapper
|
||||
@JsonSerializable()
|
||||
class FrappeSessionMessage {
|
||||
/// Session data
|
||||
final FrappeSessionData data;
|
||||
|
||||
const FrappeSessionMessage({
|
||||
required this.data,
|
||||
});
|
||||
|
||||
factory FrappeSessionMessage.fromJson(Map<String, dynamic> json) =>
|
||||
_$FrappeSessionMessageFromJson(json);
|
||||
|
||||
Map<String, dynamic> toJson() => _$FrappeSessionMessageToJson(this);
|
||||
}
|
||||
|
||||
/// Frappe Session Response
|
||||
///
|
||||
/// API response from get_session endpoint.
|
||||
/// Example:
|
||||
/// ```json
|
||||
/// {
|
||||
/// "message": {
|
||||
/// "data": {
|
||||
/// "sid": "edb6059ecf147f268176cd4aff8ca034a75ebb8ff23464f9913c9537",
|
||||
/// "csrf_token": "d0077178c349f69bc1456401d9a3d90ef0f7b9df3e08cfd26794a53f"
|
||||
/// }
|
||||
/// },
|
||||
/// "home_page": "/app",
|
||||
/// "full_name": "PublicAPI"
|
||||
/// }
|
||||
/// ```
|
||||
@JsonSerializable()
|
||||
class FrappeSessionResponse {
|
||||
/// Message containing session data
|
||||
final FrappeSessionMessage message;
|
||||
|
||||
/// Home page path
|
||||
@JsonKey(name: 'home_page')
|
||||
final String homePage;
|
||||
|
||||
/// Full name of the API user
|
||||
@JsonKey(name: 'full_name')
|
||||
final String fullName;
|
||||
|
||||
const FrappeSessionResponse({
|
||||
required this.message,
|
||||
required this.homePage,
|
||||
required this.fullName,
|
||||
});
|
||||
|
||||
factory FrappeSessionResponse.fromJson(Map<String, dynamic> json) =>
|
||||
_$FrappeSessionResponseFromJson(json);
|
||||
|
||||
Map<String, dynamic> toJson() => _$FrappeSessionResponseToJson(this);
|
||||
|
||||
/// Get session ID
|
||||
String get sid => message.data.sid;
|
||||
|
||||
/// Get CSRF token
|
||||
String get csrfToken => message.data.csrfToken;
|
||||
}
|
||||
62
lib/core/models/frappe_session_model.g.dart
Normal file
62
lib/core/models/frappe_session_model.g.dart
Normal file
@@ -0,0 +1,62 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'frappe_session_model.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
FrappeSessionData _$FrappeSessionDataFromJson(Map<String, dynamic> json) =>
|
||||
$checkedCreate('FrappeSessionData', json, ($checkedConvert) {
|
||||
final val = FrappeSessionData(
|
||||
sid: $checkedConvert('sid', (v) => v as String),
|
||||
csrfToken: $checkedConvert('csrf_token', (v) => v as String),
|
||||
);
|
||||
return val;
|
||||
}, fieldKeyMap: const {'csrfToken': 'csrf_token'});
|
||||
|
||||
Map<String, dynamic> _$FrappeSessionDataToJson(FrappeSessionData instance) =>
|
||||
<String, dynamic>{'sid': instance.sid, 'csrf_token': instance.csrfToken};
|
||||
|
||||
FrappeSessionMessage _$FrappeSessionMessageFromJson(
|
||||
Map<String, dynamic> json,
|
||||
) => $checkedCreate('FrappeSessionMessage', json, ($checkedConvert) {
|
||||
final val = FrappeSessionMessage(
|
||||
data: $checkedConvert(
|
||||
'data',
|
||||
(v) => FrappeSessionData.fromJson(v as Map<String, dynamic>),
|
||||
),
|
||||
);
|
||||
return val;
|
||||
});
|
||||
|
||||
Map<String, dynamic> _$FrappeSessionMessageToJson(
|
||||
FrappeSessionMessage instance,
|
||||
) => <String, dynamic>{'data': instance.data.toJson()};
|
||||
|
||||
FrappeSessionResponse _$FrappeSessionResponseFromJson(
|
||||
Map<String, dynamic> json,
|
||||
) => $checkedCreate(
|
||||
'FrappeSessionResponse',
|
||||
json,
|
||||
($checkedConvert) {
|
||||
final val = FrappeSessionResponse(
|
||||
message: $checkedConvert(
|
||||
'message',
|
||||
(v) => FrappeSessionMessage.fromJson(v as Map<String, dynamic>),
|
||||
),
|
||||
homePage: $checkedConvert('home_page', (v) => v as String),
|
||||
fullName: $checkedConvert('full_name', (v) => v as String),
|
||||
);
|
||||
return val;
|
||||
},
|
||||
fieldKeyMap: const {'homePage': 'home_page', 'fullName': 'full_name'},
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$FrappeSessionResponseToJson(
|
||||
FrappeSessionResponse instance,
|
||||
) => <String, dynamic>{
|
||||
'message': instance.message.toJson(),
|
||||
'home_page': instance.homePage,
|
||||
'full_name': instance.fullName,
|
||||
};
|
||||
Reference in New Issue
Block a user