mirror of
https://github.com/foss42/apidash.git
synced 2025-12-02 02:39:19 +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:
@@ -1 +1,24 @@
|
||||
import 'dart:convert';
|
||||
|
||||
enum APIType {
|
||||
rest("HTTP", "HTTP"),
|
||||
graphql("GraphQL", "GQL");
|
||||
|
||||
const APIType(this.label, this.abbr);
|
||||
final String label;
|
||||
final String abbr;
|
||||
}
|
||||
|
||||
enum APIAuthType {
|
||||
none,
|
||||
basic,
|
||||
apiKey,
|
||||
bearerToken,
|
||||
jwtBearer,
|
||||
digest,
|
||||
oauth1,
|
||||
oauth2,
|
||||
}
|
||||
|
||||
|
||||
enum EnvironmentVariableType { variable, secret }
|
||||
|
||||
17
packages/apidash_core/lib/models/api_auth_model.dart
Normal file
17
packages/apidash_core/lib/models/api_auth_model.dart
Normal file
@@ -0,0 +1,17 @@
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
|
||||
part 'api_auth_model.g.dart';
|
||||
part 'api_auth_model.freezed.dart';
|
||||
|
||||
@freezed
|
||||
class APIAuthModel with _$APIAuthModel {
|
||||
const factory APIAuthModel.none() = None;
|
||||
|
||||
const factory APIAuthModel.basic({
|
||||
required String username,
|
||||
required String password,
|
||||
}) = BasicAuth;
|
||||
|
||||
factory APIAuthModel.fromJson(Map<String, dynamic> json) =>
|
||||
_$APIAuthModelFromJson(json);
|
||||
}
|
||||
386
packages/apidash_core/lib/models/api_auth_model.freezed.dart
Normal file
386
packages/apidash_core/lib/models/api_auth_model.freezed.dart
Normal file
@@ -0,0 +1,386 @@
|
||||
// coverage:ignore-file
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
// ignore_for_file: type=lint
|
||||
// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark
|
||||
|
||||
part of 'api_auth_model.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// FreezedGenerator
|
||||
// **************************************************************************
|
||||
|
||||
T _$identity<T>(T value) => value;
|
||||
|
||||
final _privateConstructorUsedError = UnsupportedError(
|
||||
'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#adding-getters-and-methods-to-our-models');
|
||||
|
||||
APIAuthModel _$APIAuthModelFromJson(Map<String, dynamic> json) {
|
||||
switch (json['runtimeType']) {
|
||||
case 'none':
|
||||
return None.fromJson(json);
|
||||
case 'basic':
|
||||
return BasicAuth.fromJson(json);
|
||||
|
||||
default:
|
||||
throw CheckedFromJsonException(json, 'runtimeType', 'APIAuthModel',
|
||||
'Invalid union type "${json['runtimeType']}"!');
|
||||
}
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
mixin _$APIAuthModel {
|
||||
@optionalTypeArgs
|
||||
TResult when<TResult extends Object?>({
|
||||
required TResult Function() none,
|
||||
required TResult Function(String username, String password) basic,
|
||||
}) =>
|
||||
throw _privateConstructorUsedError;
|
||||
@optionalTypeArgs
|
||||
TResult? whenOrNull<TResult extends Object?>({
|
||||
TResult? Function()? none,
|
||||
TResult? Function(String username, String password)? basic,
|
||||
}) =>
|
||||
throw _privateConstructorUsedError;
|
||||
@optionalTypeArgs
|
||||
TResult maybeWhen<TResult extends Object?>({
|
||||
TResult Function()? none,
|
||||
TResult Function(String username, String password)? basic,
|
||||
required TResult orElse(),
|
||||
}) =>
|
||||
throw _privateConstructorUsedError;
|
||||
@optionalTypeArgs
|
||||
TResult map<TResult extends Object?>({
|
||||
required TResult Function(None value) none,
|
||||
required TResult Function(BasicAuth value) basic,
|
||||
}) =>
|
||||
throw _privateConstructorUsedError;
|
||||
@optionalTypeArgs
|
||||
TResult? mapOrNull<TResult extends Object?>({
|
||||
TResult? Function(None value)? none,
|
||||
TResult? Function(BasicAuth value)? basic,
|
||||
}) =>
|
||||
throw _privateConstructorUsedError;
|
||||
@optionalTypeArgs
|
||||
TResult maybeMap<TResult extends Object?>({
|
||||
TResult Function(None value)? none,
|
||||
TResult Function(BasicAuth value)? basic,
|
||||
required TResult orElse(),
|
||||
}) =>
|
||||
throw _privateConstructorUsedError;
|
||||
|
||||
/// Serializes this APIAuthModel to a JSON map.
|
||||
Map<String, dynamic> toJson() => throw _privateConstructorUsedError;
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract class $APIAuthModelCopyWith<$Res> {
|
||||
factory $APIAuthModelCopyWith(
|
||||
APIAuthModel value, $Res Function(APIAuthModel) then) =
|
||||
_$APIAuthModelCopyWithImpl<$Res, APIAuthModel>;
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
class _$APIAuthModelCopyWithImpl<$Res, $Val extends APIAuthModel>
|
||||
implements $APIAuthModelCopyWith<$Res> {
|
||||
_$APIAuthModelCopyWithImpl(this._value, this._then);
|
||||
|
||||
// ignore: unused_field
|
||||
final $Val _value;
|
||||
// ignore: unused_field
|
||||
final $Res Function($Val) _then;
|
||||
|
||||
/// Create a copy of APIAuthModel
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract class _$$NoneImplCopyWith<$Res> {
|
||||
factory _$$NoneImplCopyWith(
|
||||
_$NoneImpl value, $Res Function(_$NoneImpl) then) =
|
||||
__$$NoneImplCopyWithImpl<$Res>;
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
class __$$NoneImplCopyWithImpl<$Res>
|
||||
extends _$APIAuthModelCopyWithImpl<$Res, _$NoneImpl>
|
||||
implements _$$NoneImplCopyWith<$Res> {
|
||||
__$$NoneImplCopyWithImpl(_$NoneImpl _value, $Res Function(_$NoneImpl) _then)
|
||||
: super(_value, _then);
|
||||
|
||||
/// Create a copy of APIAuthModel
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
@JsonSerializable()
|
||||
class _$NoneImpl implements None {
|
||||
const _$NoneImpl({final String? $type}) : $type = $type ?? 'none';
|
||||
|
||||
factory _$NoneImpl.fromJson(Map<String, dynamic> json) =>
|
||||
_$$NoneImplFromJson(json);
|
||||
|
||||
@JsonKey(name: 'runtimeType')
|
||||
final String $type;
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'APIAuthModel.none()';
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return identical(this, other) ||
|
||||
(other.runtimeType == runtimeType && other is _$NoneImpl);
|
||||
}
|
||||
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
@override
|
||||
int get hashCode => runtimeType.hashCode;
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult when<TResult extends Object?>({
|
||||
required TResult Function() none,
|
||||
required TResult Function(String username, String password) basic,
|
||||
}) {
|
||||
return none();
|
||||
}
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult? whenOrNull<TResult extends Object?>({
|
||||
TResult? Function()? none,
|
||||
TResult? Function(String username, String password)? basic,
|
||||
}) {
|
||||
return none?.call();
|
||||
}
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult maybeWhen<TResult extends Object?>({
|
||||
TResult Function()? none,
|
||||
TResult Function(String username, String password)? basic,
|
||||
required TResult orElse(),
|
||||
}) {
|
||||
if (none != null) {
|
||||
return none();
|
||||
}
|
||||
return orElse();
|
||||
}
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult map<TResult extends Object?>({
|
||||
required TResult Function(None value) none,
|
||||
required TResult Function(BasicAuth value) basic,
|
||||
}) {
|
||||
return none(this);
|
||||
}
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult? mapOrNull<TResult extends Object?>({
|
||||
TResult? Function(None value)? none,
|
||||
TResult? Function(BasicAuth value)? basic,
|
||||
}) {
|
||||
return none?.call(this);
|
||||
}
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult maybeMap<TResult extends Object?>({
|
||||
TResult Function(None value)? none,
|
||||
TResult Function(BasicAuth value)? basic,
|
||||
required TResult orElse(),
|
||||
}) {
|
||||
if (none != null) {
|
||||
return none(this);
|
||||
}
|
||||
return orElse();
|
||||
}
|
||||
|
||||
@override
|
||||
Map<String, dynamic> toJson() {
|
||||
return _$$NoneImplToJson(
|
||||
this,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
abstract class None implements APIAuthModel {
|
||||
const factory None() = _$NoneImpl;
|
||||
|
||||
factory None.fromJson(Map<String, dynamic> json) = _$NoneImpl.fromJson;
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract class _$$BasicAuthImplCopyWith<$Res> {
|
||||
factory _$$BasicAuthImplCopyWith(
|
||||
_$BasicAuthImpl value, $Res Function(_$BasicAuthImpl) then) =
|
||||
__$$BasicAuthImplCopyWithImpl<$Res>;
|
||||
@useResult
|
||||
$Res call({String username, String password});
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
class __$$BasicAuthImplCopyWithImpl<$Res>
|
||||
extends _$APIAuthModelCopyWithImpl<$Res, _$BasicAuthImpl>
|
||||
implements _$$BasicAuthImplCopyWith<$Res> {
|
||||
__$$BasicAuthImplCopyWithImpl(
|
||||
_$BasicAuthImpl _value, $Res Function(_$BasicAuthImpl) _then)
|
||||
: super(_value, _then);
|
||||
|
||||
/// Create a copy of APIAuthModel
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@pragma('vm:prefer-inline')
|
||||
@override
|
||||
$Res call({
|
||||
Object? username = null,
|
||||
Object? password = null,
|
||||
}) {
|
||||
return _then(_$BasicAuthImpl(
|
||||
username: null == username
|
||||
? _value.username
|
||||
: username // ignore: cast_nullable_to_non_nullable
|
||||
as String,
|
||||
password: null == password
|
||||
? _value.password
|
||||
: password // ignore: cast_nullable_to_non_nullable
|
||||
as String,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
@JsonSerializable()
|
||||
class _$BasicAuthImpl implements BasicAuth {
|
||||
const _$BasicAuthImpl(
|
||||
{required this.username, required this.password, final String? $type})
|
||||
: $type = $type ?? 'basic';
|
||||
|
||||
factory _$BasicAuthImpl.fromJson(Map<String, dynamic> json) =>
|
||||
_$$BasicAuthImplFromJson(json);
|
||||
|
||||
@override
|
||||
final String username;
|
||||
@override
|
||||
final String password;
|
||||
|
||||
@JsonKey(name: 'runtimeType')
|
||||
final String $type;
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'APIAuthModel.basic(username: $username, password: $password)';
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return identical(this, other) ||
|
||||
(other.runtimeType == runtimeType &&
|
||||
other is _$BasicAuthImpl &&
|
||||
(identical(other.username, username) ||
|
||||
other.username == username) &&
|
||||
(identical(other.password, password) ||
|
||||
other.password == password));
|
||||
}
|
||||
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
@override
|
||||
int get hashCode => Object.hash(runtimeType, username, password);
|
||||
|
||||
/// Create a copy of APIAuthModel
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
@override
|
||||
@pragma('vm:prefer-inline')
|
||||
_$$BasicAuthImplCopyWith<_$BasicAuthImpl> get copyWith =>
|
||||
__$$BasicAuthImplCopyWithImpl<_$BasicAuthImpl>(this, _$identity);
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult when<TResult extends Object?>({
|
||||
required TResult Function() none,
|
||||
required TResult Function(String username, String password) basic,
|
||||
}) {
|
||||
return basic(username, password);
|
||||
}
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult? whenOrNull<TResult extends Object?>({
|
||||
TResult? Function()? none,
|
||||
TResult? Function(String username, String password)? basic,
|
||||
}) {
|
||||
return basic?.call(username, password);
|
||||
}
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult maybeWhen<TResult extends Object?>({
|
||||
TResult Function()? none,
|
||||
TResult Function(String username, String password)? basic,
|
||||
required TResult orElse(),
|
||||
}) {
|
||||
if (basic != null) {
|
||||
return basic(username, password);
|
||||
}
|
||||
return orElse();
|
||||
}
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult map<TResult extends Object?>({
|
||||
required TResult Function(None value) none,
|
||||
required TResult Function(BasicAuth value) basic,
|
||||
}) {
|
||||
return basic(this);
|
||||
}
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult? mapOrNull<TResult extends Object?>({
|
||||
TResult? Function(None value)? none,
|
||||
TResult? Function(BasicAuth value)? basic,
|
||||
}) {
|
||||
return basic?.call(this);
|
||||
}
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult maybeMap<TResult extends Object?>({
|
||||
TResult Function(None value)? none,
|
||||
TResult Function(BasicAuth value)? basic,
|
||||
required TResult orElse(),
|
||||
}) {
|
||||
if (basic != null) {
|
||||
return basic(this);
|
||||
}
|
||||
return orElse();
|
||||
}
|
||||
|
||||
@override
|
||||
Map<String, dynamic> toJson() {
|
||||
return _$$BasicAuthImplToJson(
|
||||
this,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
abstract class BasicAuth implements APIAuthModel {
|
||||
const factory BasicAuth(
|
||||
{required final String username,
|
||||
required final String password}) = _$BasicAuthImpl;
|
||||
|
||||
factory BasicAuth.fromJson(Map<String, dynamic> json) =
|
||||
_$BasicAuthImpl.fromJson;
|
||||
|
||||
String get username;
|
||||
String get password;
|
||||
|
||||
/// Create a copy of APIAuthModel
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
_$$BasicAuthImplCopyWith<_$BasicAuthImpl> get copyWith =>
|
||||
throw _privateConstructorUsedError;
|
||||
}
|
||||
30
packages/apidash_core/lib/models/api_auth_model.g.dart
Normal file
30
packages/apidash_core/lib/models/api_auth_model.g.dart
Normal file
@@ -0,0 +1,30 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'api_auth_model.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
_$NoneImpl _$$NoneImplFromJson(Map<String, dynamic> json) => _$NoneImpl(
|
||||
$type: json['runtimeType'] as String?,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$$NoneImplToJson(_$NoneImpl instance) =>
|
||||
<String, dynamic>{
|
||||
'runtimeType': instance.$type,
|
||||
};
|
||||
|
||||
_$BasicAuthImpl _$$BasicAuthImplFromJson(Map<String, dynamic> json) =>
|
||||
_$BasicAuthImpl(
|
||||
username: json['username'] as String,
|
||||
password: json['password'] as String,
|
||||
$type: json['runtimeType'] as String?,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$$BasicAuthImplToJson(_$BasicAuthImpl instance) =>
|
||||
<String, dynamic>{
|
||||
'username': instance.username,
|
||||
'password': instance.password,
|
||||
'runtimeType': instance.$type,
|
||||
};
|
||||
@@ -1 +1,4 @@
|
||||
export 'environment_model.dart';
|
||||
export 'http_request_model.dart';
|
||||
export 'http_response_model.dart';
|
||||
export 'api_auth_model.dart';
|
||||
Reference in New Issue
Block a user