mirror of
https://github.com/foss42/apidash.git
synced 2025-12-02 10:49:49 +08:00
feat: add authentication support with APIAuthType and APIAuthModel
- Introduced APIAuthType enum for various authentication methods. - Created APIAuthModel with basic authentication fields. - Updated RequestModel to include authType and authData. - Implemented EditAuthType widget for selecting and managing authentication. - Enhanced CollectionStateNotifier to handle authentication updates. :wq
This commit is contained in:
@@ -15,6 +15,8 @@ class RequestModel with _$RequestModel {
|
||||
@Default(APIType.rest) APIType apiType,
|
||||
@Default("") String name,
|
||||
@Default("") String description,
|
||||
@Default(APIAuthType.none) APIAuthType authType,
|
||||
APIAuthModel? authData,
|
||||
@JsonKey(includeToJson: false) @Default(0) requestTabIndex,
|
||||
HttpRequestModel? httpRequestModel,
|
||||
int? responseStatus,
|
||||
|
||||
@@ -24,6 +24,8 @@ mixin _$RequestModel {
|
||||
APIType get apiType => throw _privateConstructorUsedError;
|
||||
String get name => throw _privateConstructorUsedError;
|
||||
String get description => throw _privateConstructorUsedError;
|
||||
APIAuthType get authType => throw _privateConstructorUsedError;
|
||||
APIAuthModel? get authData => throw _privateConstructorUsedError;
|
||||
@JsonKey(includeToJson: false)
|
||||
dynamic get requestTabIndex => throw _privateConstructorUsedError;
|
||||
HttpRequestModel? get httpRequestModel => throw _privateConstructorUsedError;
|
||||
@@ -59,6 +61,8 @@ abstract class $RequestModelCopyWith<$Res> {
|
||||
APIType apiType,
|
||||
String name,
|
||||
String description,
|
||||
APIAuthType authType,
|
||||
APIAuthModel? authData,
|
||||
@JsonKey(includeToJson: false) dynamic requestTabIndex,
|
||||
HttpRequestModel? httpRequestModel,
|
||||
int? responseStatus,
|
||||
@@ -69,6 +73,7 @@ abstract class $RequestModelCopyWith<$Res> {
|
||||
String? preRequestScript,
|
||||
String? postRequestScript});
|
||||
|
||||
$APIAuthModelCopyWith<$Res>? get authData;
|
||||
$HttpRequestModelCopyWith<$Res>? get httpRequestModel;
|
||||
$HttpResponseModelCopyWith<$Res>? get httpResponseModel;
|
||||
}
|
||||
@@ -92,6 +97,8 @@ class _$RequestModelCopyWithImpl<$Res, $Val extends RequestModel>
|
||||
Object? apiType = null,
|
||||
Object? name = null,
|
||||
Object? description = null,
|
||||
Object? authType = null,
|
||||
Object? authData = freezed,
|
||||
Object? requestTabIndex = freezed,
|
||||
Object? httpRequestModel = freezed,
|
||||
Object? responseStatus = freezed,
|
||||
@@ -119,6 +126,14 @@ class _$RequestModelCopyWithImpl<$Res, $Val extends RequestModel>
|
||||
? _value.description
|
||||
: description // ignore: cast_nullable_to_non_nullable
|
||||
as String,
|
||||
authType: null == authType
|
||||
? _value.authType
|
||||
: authType // ignore: cast_nullable_to_non_nullable
|
||||
as APIAuthType,
|
||||
authData: freezed == authData
|
||||
? _value.authData
|
||||
: authData // ignore: cast_nullable_to_non_nullable
|
||||
as APIAuthModel?,
|
||||
requestTabIndex: freezed == requestTabIndex
|
||||
? _value.requestTabIndex
|
||||
: requestTabIndex // ignore: cast_nullable_to_non_nullable
|
||||
@@ -158,6 +173,20 @@ class _$RequestModelCopyWithImpl<$Res, $Val extends RequestModel>
|
||||
) as $Val);
|
||||
}
|
||||
|
||||
/// Create a copy of RequestModel
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@override
|
||||
@pragma('vm:prefer-inline')
|
||||
$APIAuthModelCopyWith<$Res>? get authData {
|
||||
if (_value.authData == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $APIAuthModelCopyWith<$Res>(_value.authData!, (value) {
|
||||
return _then(_value.copyWith(authData: value) as $Val);
|
||||
});
|
||||
}
|
||||
|
||||
/// Create a copy of RequestModel
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@override
|
||||
@@ -200,6 +229,8 @@ abstract class _$$RequestModelImplCopyWith<$Res>
|
||||
APIType apiType,
|
||||
String name,
|
||||
String description,
|
||||
APIAuthType authType,
|
||||
APIAuthModel? authData,
|
||||
@JsonKey(includeToJson: false) dynamic requestTabIndex,
|
||||
HttpRequestModel? httpRequestModel,
|
||||
int? responseStatus,
|
||||
@@ -210,6 +241,8 @@ abstract class _$$RequestModelImplCopyWith<$Res>
|
||||
String? preRequestScript,
|
||||
String? postRequestScript});
|
||||
|
||||
@override
|
||||
$APIAuthModelCopyWith<$Res>? get authData;
|
||||
@override
|
||||
$HttpRequestModelCopyWith<$Res>? get httpRequestModel;
|
||||
@override
|
||||
@@ -233,6 +266,8 @@ class __$$RequestModelImplCopyWithImpl<$Res>
|
||||
Object? apiType = null,
|
||||
Object? name = null,
|
||||
Object? description = null,
|
||||
Object? authType = null,
|
||||
Object? authData = freezed,
|
||||
Object? requestTabIndex = freezed,
|
||||
Object? httpRequestModel = freezed,
|
||||
Object? responseStatus = freezed,
|
||||
@@ -260,6 +295,14 @@ class __$$RequestModelImplCopyWithImpl<$Res>
|
||||
? _value.description
|
||||
: description // ignore: cast_nullable_to_non_nullable
|
||||
as String,
|
||||
authType: null == authType
|
||||
? _value.authType
|
||||
: authType // ignore: cast_nullable_to_non_nullable
|
||||
as APIAuthType,
|
||||
authData: freezed == authData
|
||||
? _value.authData
|
||||
: authData // ignore: cast_nullable_to_non_nullable
|
||||
as APIAuthModel?,
|
||||
requestTabIndex: freezed == requestTabIndex
|
||||
? _value.requestTabIndex!
|
||||
: requestTabIndex,
|
||||
@@ -308,6 +351,8 @@ class _$RequestModelImpl implements _RequestModel {
|
||||
this.apiType = APIType.rest,
|
||||
this.name = "",
|
||||
this.description = "",
|
||||
this.authType = APIAuthType.none,
|
||||
this.authData,
|
||||
@JsonKey(includeToJson: false) this.requestTabIndex = 0,
|
||||
this.httpRequestModel,
|
||||
this.responseStatus,
|
||||
@@ -333,6 +378,11 @@ class _$RequestModelImpl implements _RequestModel {
|
||||
@JsonKey()
|
||||
final String description;
|
||||
@override
|
||||
@JsonKey()
|
||||
final APIAuthType authType;
|
||||
@override
|
||||
final APIAuthModel? authData;
|
||||
@override
|
||||
@JsonKey(includeToJson: false)
|
||||
final dynamic requestTabIndex;
|
||||
@override
|
||||
@@ -356,7 +406,7 @@ class _$RequestModelImpl implements _RequestModel {
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'RequestModel(id: $id, apiType: $apiType, name: $name, description: $description, requestTabIndex: $requestTabIndex, httpRequestModel: $httpRequestModel, responseStatus: $responseStatus, message: $message, httpResponseModel: $httpResponseModel, isWorking: $isWorking, sendingTime: $sendingTime, preRequestScript: $preRequestScript, postRequestScript: $postRequestScript)';
|
||||
return 'RequestModel(id: $id, apiType: $apiType, name: $name, description: $description, authType: $authType, authData: $authData, requestTabIndex: $requestTabIndex, httpRequestModel: $httpRequestModel, responseStatus: $responseStatus, message: $message, httpResponseModel: $httpResponseModel, isWorking: $isWorking, sendingTime: $sendingTime)';
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -369,6 +419,10 @@ class _$RequestModelImpl implements _RequestModel {
|
||||
(identical(other.name, name) || other.name == name) &&
|
||||
(identical(other.description, description) ||
|
||||
other.description == description) &&
|
||||
(identical(other.authType, authType) ||
|
||||
other.authType == authType) &&
|
||||
(identical(other.authData, authData) ||
|
||||
other.authData == authData) &&
|
||||
const DeepCollectionEquality()
|
||||
.equals(other.requestTabIndex, requestTabIndex) &&
|
||||
(identical(other.httpRequestModel, httpRequestModel) ||
|
||||
@@ -396,6 +450,8 @@ class _$RequestModelImpl implements _RequestModel {
|
||||
apiType,
|
||||
name,
|
||||
description,
|
||||
authType,
|
||||
authData,
|
||||
const DeepCollectionEquality().hash(requestTabIndex),
|
||||
httpRequestModel,
|
||||
responseStatus,
|
||||
@@ -424,19 +480,20 @@ class _$RequestModelImpl implements _RequestModel {
|
||||
|
||||
abstract class _RequestModel implements RequestModel {
|
||||
const factory _RequestModel(
|
||||
{required final String id,
|
||||
final APIType apiType,
|
||||
final String name,
|
||||
final String description,
|
||||
@JsonKey(includeToJson: false) final dynamic requestTabIndex,
|
||||
final HttpRequestModel? httpRequestModel,
|
||||
final int? responseStatus,
|
||||
final String? message,
|
||||
final HttpResponseModel? httpResponseModel,
|
||||
@JsonKey(includeToJson: false) final bool isWorking,
|
||||
@JsonKey(includeToJson: false) final DateTime? sendingTime,
|
||||
final String? preRequestScript,
|
||||
final String? postRequestScript}) = _$RequestModelImpl;
|
||||
{required final String id,
|
||||
final APIType apiType,
|
||||
final String name,
|
||||
final String description,
|
||||
final APIAuthType authType,
|
||||
final APIAuthModel? authData,
|
||||
@JsonKey(includeToJson: false) final dynamic requestTabIndex,
|
||||
final HttpRequestModel? httpRequestModel,
|
||||
final int? responseStatus,
|
||||
final String? message,
|
||||
final HttpResponseModel? httpResponseModel,
|
||||
@JsonKey(includeToJson: false) final bool isWorking,
|
||||
@JsonKey(includeToJson: false) final DateTime? sendingTime}) =
|
||||
_$RequestModelImpl;
|
||||
|
||||
factory _RequestModel.fromJson(Map<String, dynamic> json) =
|
||||
_$RequestModelImpl.fromJson;
|
||||
@@ -450,6 +507,10 @@ abstract class _RequestModel implements RequestModel {
|
||||
@override
|
||||
String get description;
|
||||
@override
|
||||
APIAuthType get authType;
|
||||
@override
|
||||
APIAuthModel? get authData;
|
||||
@override
|
||||
@JsonKey(includeToJson: false)
|
||||
dynamic get requestTabIndex;
|
||||
@override
|
||||
|
||||
@@ -12,6 +12,12 @@ _$RequestModelImpl _$$RequestModelImplFromJson(Map json) => _$RequestModelImpl(
|
||||
APIType.rest,
|
||||
name: json['name'] as String? ?? "",
|
||||
description: json['description'] as String? ?? "",
|
||||
authType: $enumDecodeNullable(_$APIAuthTypeEnumMap, json['authType']) ??
|
||||
APIAuthType.none,
|
||||
authData: json['authData'] == null
|
||||
? null
|
||||
: APIAuthModel.fromJson(
|
||||
Map<String, dynamic>.from(json['authData'] as Map)),
|
||||
requestTabIndex: json['requestTabIndex'] ?? 0,
|
||||
httpRequestModel: json['httpRequestModel'] == null
|
||||
? null
|
||||
@@ -37,6 +43,8 @@ Map<String, dynamic> _$$RequestModelImplToJson(_$RequestModelImpl instance) =>
|
||||
'apiType': _$APITypeEnumMap[instance.apiType]!,
|
||||
'name': instance.name,
|
||||
'description': instance.description,
|
||||
'authType': _$APIAuthTypeEnumMap[instance.authType]!,
|
||||
'authData': instance.authData?.toJson(),
|
||||
'httpRequestModel': instance.httpRequestModel?.toJson(),
|
||||
'responseStatus': instance.responseStatus,
|
||||
'message': instance.message,
|
||||
@@ -49,3 +57,14 @@ const _$APITypeEnumMap = {
|
||||
APIType.rest: 'rest',
|
||||
APIType.graphql: 'graphql',
|
||||
};
|
||||
|
||||
const _$APIAuthTypeEnumMap = {
|
||||
APIAuthType.none: 'none',
|
||||
APIAuthType.basic: 'basic',
|
||||
APIAuthType.apiKey: 'apiKey',
|
||||
APIAuthType.bearerToken: 'bearerToken',
|
||||
APIAuthType.jwtBearer: 'jwtBearer',
|
||||
APIAuthType.digest: 'digest',
|
||||
APIAuthType.oauth1: 'oauth1',
|
||||
APIAuthType.oauth2: 'oauth2',
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user