feat: add oauth1 model

This commit is contained in:
Udhay-Adithya
2025-07-21 23:14:15 +05:30
parent f458d00341
commit 8eda23dc3b
8 changed files with 577 additions and 75 deletions

View File

@@ -5,6 +5,7 @@ import 'auth_basic_model.dart';
import 'auth_bearer_model.dart';
import 'auth_jwt_model.dart';
import 'auth_digest_model.dart';
import 'auth_oauth1_model.dart';
import 'auth_oauth2_model.dart';
part 'api_auth_model.g.dart';
@@ -20,6 +21,7 @@ class AuthModel with _$AuthModel {
AuthBasicAuthModel? basic,
AuthJwtModel? jwt,
AuthDigestModel? digest,
AuthOAuth1Model? oauth1,
AuthOAuth2Model? oauth2,
}) = _AuthModel;

View File

@@ -27,6 +27,7 @@ mixin _$AuthModel {
AuthBasicAuthModel? get basic => throw _privateConstructorUsedError;
AuthJwtModel? get jwt => throw _privateConstructorUsedError;
AuthDigestModel? get digest => throw _privateConstructorUsedError;
AuthOAuth1Model? get oauth1 => throw _privateConstructorUsedError;
AuthOAuth2Model? get oauth2 => throw _privateConstructorUsedError;
/// Serializes this AuthModel to a JSON map.
@@ -51,6 +52,7 @@ abstract class $AuthModelCopyWith<$Res> {
AuthBasicAuthModel? basic,
AuthJwtModel? jwt,
AuthDigestModel? digest,
AuthOAuth1Model? oauth1,
AuthOAuth2Model? oauth2,
});
@@ -59,6 +61,7 @@ abstract class $AuthModelCopyWith<$Res> {
$AuthBasicAuthModelCopyWith<$Res>? get basic;
$AuthJwtModelCopyWith<$Res>? get jwt;
$AuthDigestModelCopyWith<$Res>? get digest;
$AuthOAuth1ModelCopyWith<$Res>? get oauth1;
$AuthOAuth2ModelCopyWith<$Res>? get oauth2;
}
@@ -83,6 +86,7 @@ class _$AuthModelCopyWithImpl<$Res, $Val extends AuthModel>
Object? basic = freezed,
Object? jwt = freezed,
Object? digest = freezed,
Object? oauth1 = freezed,
Object? oauth2 = freezed,
}) {
return _then(
@@ -111,6 +115,10 @@ class _$AuthModelCopyWithImpl<$Res, $Val extends AuthModel>
? _value.digest
: digest // ignore: cast_nullable_to_non_nullable
as AuthDigestModel?,
oauth1: freezed == oauth1
? _value.oauth1
: oauth1 // ignore: cast_nullable_to_non_nullable
as AuthOAuth1Model?,
oauth2: freezed == oauth2
? _value.oauth2
: oauth2 // ignore: cast_nullable_to_non_nullable
@@ -190,6 +198,20 @@ class _$AuthModelCopyWithImpl<$Res, $Val extends AuthModel>
});
}
/// Create a copy of AuthModel
/// with the given fields replaced by the non-null parameter values.
@override
@pragma('vm:prefer-inline')
$AuthOAuth1ModelCopyWith<$Res>? get oauth1 {
if (_value.oauth1 == null) {
return null;
}
return $AuthOAuth1ModelCopyWith<$Res>(_value.oauth1!, (value) {
return _then(_value.copyWith(oauth1: value) as $Val);
});
}
/// Create a copy of AuthModel
/// with the given fields replaced by the non-null parameter values.
@override
@@ -221,6 +243,7 @@ abstract class _$$AuthModelImplCopyWith<$Res>
AuthBasicAuthModel? basic,
AuthJwtModel? jwt,
AuthDigestModel? digest,
AuthOAuth1Model? oauth1,
AuthOAuth2Model? oauth2,
});
@@ -235,6 +258,8 @@ abstract class _$$AuthModelImplCopyWith<$Res>
@override
$AuthDigestModelCopyWith<$Res>? get digest;
@override
$AuthOAuth1ModelCopyWith<$Res>? get oauth1;
@override
$AuthOAuth2ModelCopyWith<$Res>? get oauth2;
}
@@ -258,6 +283,7 @@ class __$$AuthModelImplCopyWithImpl<$Res>
Object? basic = freezed,
Object? jwt = freezed,
Object? digest = freezed,
Object? oauth1 = freezed,
Object? oauth2 = freezed,
}) {
return _then(
@@ -286,6 +312,10 @@ class __$$AuthModelImplCopyWithImpl<$Res>
? _value.digest
: digest // ignore: cast_nullable_to_non_nullable
as AuthDigestModel?,
oauth1: freezed == oauth1
? _value.oauth1
: oauth1 // ignore: cast_nullable_to_non_nullable
as AuthOAuth1Model?,
oauth2: freezed == oauth2
? _value.oauth2
: oauth2 // ignore: cast_nullable_to_non_nullable
@@ -306,6 +336,7 @@ class _$AuthModelImpl implements _AuthModel {
this.basic,
this.jwt,
this.digest,
this.oauth1,
this.oauth2,
});
@@ -325,11 +356,13 @@ class _$AuthModelImpl implements _AuthModel {
@override
final AuthDigestModel? digest;
@override
final AuthOAuth1Model? oauth1;
@override
final AuthOAuth2Model? oauth2;
@override
String toString() {
return 'AuthModel(type: $type, apikey: $apikey, bearer: $bearer, basic: $basic, jwt: $jwt, digest: $digest, oauth2: $oauth2)';
return 'AuthModel(type: $type, apikey: $apikey, bearer: $bearer, basic: $basic, jwt: $jwt, digest: $digest, oauth1: $oauth1, oauth2: $oauth2)';
}
@override
@@ -343,6 +376,7 @@ class _$AuthModelImpl implements _AuthModel {
(identical(other.basic, basic) || other.basic == basic) &&
(identical(other.jwt, jwt) || other.jwt == jwt) &&
(identical(other.digest, digest) || other.digest == digest) &&
(identical(other.oauth1, oauth1) || other.oauth1 == oauth1) &&
(identical(other.oauth2, oauth2) || other.oauth2 == oauth2));
}
@@ -356,6 +390,7 @@ class _$AuthModelImpl implements _AuthModel {
basic,
jwt,
digest,
oauth1,
oauth2,
);
@@ -381,6 +416,7 @@ abstract class _AuthModel implements AuthModel {
final AuthBasicAuthModel? basic,
final AuthJwtModel? jwt,
final AuthDigestModel? digest,
final AuthOAuth1Model? oauth1,
final AuthOAuth2Model? oauth2,
}) = _$AuthModelImpl;
@@ -400,6 +436,8 @@ abstract class _AuthModel implements AuthModel {
@override
AuthDigestModel? get digest;
@override
AuthOAuth1Model? get oauth1;
@override
AuthOAuth2Model? get oauth2;
/// Create a copy of AuthModel

View File

@@ -31,6 +31,11 @@ _$AuthModelImpl _$$AuthModelImplFromJson(Map json) => _$AuthModelImpl(
: AuthDigestModel.fromJson(
Map<String, dynamic>.from(json['digest'] as Map),
),
oauth1: json['oauth1'] == null
? null
: AuthOAuth1Model.fromJson(
Map<String, dynamic>.from(json['oauth1'] as Map),
),
oauth2: json['oauth2'] == null
? null
: AuthOAuth2Model.fromJson(
@@ -46,6 +51,7 @@ Map<String, dynamic> _$$AuthModelImplToJson(_$AuthModelImpl instance) =>
'basic': instance.basic?.toJson(),
'jwt': instance.jwt?.toJson(),
'digest': instance.digest?.toJson(),
'oauth1': instance.oauth1?.toJson(),
'oauth2': instance.oauth2?.toJson(),
};

View File

@@ -0,0 +1,27 @@
import 'package:freezed_annotation/freezed_annotation.dart';
part 'auth_oauth1_model.g.dart';
part 'auth_oauth1_model.freezed.dart';
@freezed
class AuthOAuth1Model with _$AuthOAuth1Model {
const factory AuthOAuth1Model({
required String consumerKey,
required String consumerSecret,
String? accessToken,
String? tokenSecret,
@Default("hmacSha1") String signatureMethod,
@Default("header") String parameterLocation,
@Default('1.0') String version,
String? realm,
String? callbackUrl,
String? verifier,
String? nonce,
String? timestamp,
@Default(false) bool includeBodyHash,
}) = _AuthOAuth1Model;
factory AuthOAuth1Model.fromJson(Map<String, dynamic> json) =>
_$AuthOAuth1ModelFromJson(json);
}

View File

@@ -0,0 +1,451 @@
// 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 'auth_oauth1_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',
);
AuthOAuth1Model _$AuthOAuth1ModelFromJson(Map<String, dynamic> json) {
return _AuthOAuth1Model.fromJson(json);
}
/// @nodoc
mixin _$AuthOAuth1Model {
String get consumerKey => throw _privateConstructorUsedError;
String get consumerSecret => throw _privateConstructorUsedError;
String? get accessToken => throw _privateConstructorUsedError;
String? get tokenSecret => throw _privateConstructorUsedError;
String get signatureMethod => throw _privateConstructorUsedError;
String get parameterLocation => throw _privateConstructorUsedError;
String get version => throw _privateConstructorUsedError;
String? get realm => throw _privateConstructorUsedError;
String? get callbackUrl => throw _privateConstructorUsedError;
String? get verifier => throw _privateConstructorUsedError;
String? get nonce => throw _privateConstructorUsedError;
String? get timestamp => throw _privateConstructorUsedError;
bool get includeBodyHash => throw _privateConstructorUsedError;
/// Serializes this AuthOAuth1Model to a JSON map.
Map<String, dynamic> toJson() => throw _privateConstructorUsedError;
/// Create a copy of AuthOAuth1Model
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
$AuthOAuth1ModelCopyWith<AuthOAuth1Model> get copyWith =>
throw _privateConstructorUsedError;
}
/// @nodoc
abstract class $AuthOAuth1ModelCopyWith<$Res> {
factory $AuthOAuth1ModelCopyWith(
AuthOAuth1Model value,
$Res Function(AuthOAuth1Model) then,
) = _$AuthOAuth1ModelCopyWithImpl<$Res, AuthOAuth1Model>;
@useResult
$Res call({
String consumerKey,
String consumerSecret,
String? accessToken,
String? tokenSecret,
String signatureMethod,
String parameterLocation,
String version,
String? realm,
String? callbackUrl,
String? verifier,
String? nonce,
String? timestamp,
bool includeBodyHash,
});
}
/// @nodoc
class _$AuthOAuth1ModelCopyWithImpl<$Res, $Val extends AuthOAuth1Model>
implements $AuthOAuth1ModelCopyWith<$Res> {
_$AuthOAuth1ModelCopyWithImpl(this._value, this._then);
// ignore: unused_field
final $Val _value;
// ignore: unused_field
final $Res Function($Val) _then;
/// Create a copy of AuthOAuth1Model
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
Object? consumerKey = null,
Object? consumerSecret = null,
Object? accessToken = freezed,
Object? tokenSecret = freezed,
Object? signatureMethod = null,
Object? parameterLocation = null,
Object? version = null,
Object? realm = freezed,
Object? callbackUrl = freezed,
Object? verifier = freezed,
Object? nonce = freezed,
Object? timestamp = freezed,
Object? includeBodyHash = null,
}) {
return _then(
_value.copyWith(
consumerKey: null == consumerKey
? _value.consumerKey
: consumerKey // ignore: cast_nullable_to_non_nullable
as String,
consumerSecret: null == consumerSecret
? _value.consumerSecret
: consumerSecret // ignore: cast_nullable_to_non_nullable
as String,
accessToken: freezed == accessToken
? _value.accessToken
: accessToken // ignore: cast_nullable_to_non_nullable
as String?,
tokenSecret: freezed == tokenSecret
? _value.tokenSecret
: tokenSecret // ignore: cast_nullable_to_non_nullable
as String?,
signatureMethod: null == signatureMethod
? _value.signatureMethod
: signatureMethod // ignore: cast_nullable_to_non_nullable
as String,
parameterLocation: null == parameterLocation
? _value.parameterLocation
: parameterLocation // ignore: cast_nullable_to_non_nullable
as String,
version: null == version
? _value.version
: version // ignore: cast_nullable_to_non_nullable
as String,
realm: freezed == realm
? _value.realm
: realm // ignore: cast_nullable_to_non_nullable
as String?,
callbackUrl: freezed == callbackUrl
? _value.callbackUrl
: callbackUrl // ignore: cast_nullable_to_non_nullable
as String?,
verifier: freezed == verifier
? _value.verifier
: verifier // ignore: cast_nullable_to_non_nullable
as String?,
nonce: freezed == nonce
? _value.nonce
: nonce // ignore: cast_nullable_to_non_nullable
as String?,
timestamp: freezed == timestamp
? _value.timestamp
: timestamp // ignore: cast_nullable_to_non_nullable
as String?,
includeBodyHash: null == includeBodyHash
? _value.includeBodyHash
: includeBodyHash // ignore: cast_nullable_to_non_nullable
as bool,
)
as $Val,
);
}
}
/// @nodoc
abstract class _$$AuthOAuth1ModelImplCopyWith<$Res>
implements $AuthOAuth1ModelCopyWith<$Res> {
factory _$$AuthOAuth1ModelImplCopyWith(
_$AuthOAuth1ModelImpl value,
$Res Function(_$AuthOAuth1ModelImpl) then,
) = __$$AuthOAuth1ModelImplCopyWithImpl<$Res>;
@override
@useResult
$Res call({
String consumerKey,
String consumerSecret,
String? accessToken,
String? tokenSecret,
String signatureMethod,
String parameterLocation,
String version,
String? realm,
String? callbackUrl,
String? verifier,
String? nonce,
String? timestamp,
bool includeBodyHash,
});
}
/// @nodoc
class __$$AuthOAuth1ModelImplCopyWithImpl<$Res>
extends _$AuthOAuth1ModelCopyWithImpl<$Res, _$AuthOAuth1ModelImpl>
implements _$$AuthOAuth1ModelImplCopyWith<$Res> {
__$$AuthOAuth1ModelImplCopyWithImpl(
_$AuthOAuth1ModelImpl _value,
$Res Function(_$AuthOAuth1ModelImpl) _then,
) : super(_value, _then);
/// Create a copy of AuthOAuth1Model
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
Object? consumerKey = null,
Object? consumerSecret = null,
Object? accessToken = freezed,
Object? tokenSecret = freezed,
Object? signatureMethod = null,
Object? parameterLocation = null,
Object? version = null,
Object? realm = freezed,
Object? callbackUrl = freezed,
Object? verifier = freezed,
Object? nonce = freezed,
Object? timestamp = freezed,
Object? includeBodyHash = null,
}) {
return _then(
_$AuthOAuth1ModelImpl(
consumerKey: null == consumerKey
? _value.consumerKey
: consumerKey // ignore: cast_nullable_to_non_nullable
as String,
consumerSecret: null == consumerSecret
? _value.consumerSecret
: consumerSecret // ignore: cast_nullable_to_non_nullable
as String,
accessToken: freezed == accessToken
? _value.accessToken
: accessToken // ignore: cast_nullable_to_non_nullable
as String?,
tokenSecret: freezed == tokenSecret
? _value.tokenSecret
: tokenSecret // ignore: cast_nullable_to_non_nullable
as String?,
signatureMethod: null == signatureMethod
? _value.signatureMethod
: signatureMethod // ignore: cast_nullable_to_non_nullable
as String,
parameterLocation: null == parameterLocation
? _value.parameterLocation
: parameterLocation // ignore: cast_nullable_to_non_nullable
as String,
version: null == version
? _value.version
: version // ignore: cast_nullable_to_non_nullable
as String,
realm: freezed == realm
? _value.realm
: realm // ignore: cast_nullable_to_non_nullable
as String?,
callbackUrl: freezed == callbackUrl
? _value.callbackUrl
: callbackUrl // ignore: cast_nullable_to_non_nullable
as String?,
verifier: freezed == verifier
? _value.verifier
: verifier // ignore: cast_nullable_to_non_nullable
as String?,
nonce: freezed == nonce
? _value.nonce
: nonce // ignore: cast_nullable_to_non_nullable
as String?,
timestamp: freezed == timestamp
? _value.timestamp
: timestamp // ignore: cast_nullable_to_non_nullable
as String?,
includeBodyHash: null == includeBodyHash
? _value.includeBodyHash
: includeBodyHash // ignore: cast_nullable_to_non_nullable
as bool,
),
);
}
}
/// @nodoc
@JsonSerializable()
class _$AuthOAuth1ModelImpl implements _AuthOAuth1Model {
const _$AuthOAuth1ModelImpl({
required this.consumerKey,
required this.consumerSecret,
this.accessToken,
this.tokenSecret,
this.signatureMethod = "hmacSha1",
this.parameterLocation = "header",
this.version = '1.0',
this.realm,
this.callbackUrl,
this.verifier,
this.nonce,
this.timestamp,
this.includeBodyHash = false,
});
factory _$AuthOAuth1ModelImpl.fromJson(Map<String, dynamic> json) =>
_$$AuthOAuth1ModelImplFromJson(json);
@override
final String consumerKey;
@override
final String consumerSecret;
@override
final String? accessToken;
@override
final String? tokenSecret;
@override
@JsonKey()
final String signatureMethod;
@override
@JsonKey()
final String parameterLocation;
@override
@JsonKey()
final String version;
@override
final String? realm;
@override
final String? callbackUrl;
@override
final String? verifier;
@override
final String? nonce;
@override
final String? timestamp;
@override
@JsonKey()
final bool includeBodyHash;
@override
String toString() {
return 'AuthOAuth1Model(consumerKey: $consumerKey, consumerSecret: $consumerSecret, accessToken: $accessToken, tokenSecret: $tokenSecret, signatureMethod: $signatureMethod, parameterLocation: $parameterLocation, version: $version, realm: $realm, callbackUrl: $callbackUrl, verifier: $verifier, nonce: $nonce, timestamp: $timestamp, includeBodyHash: $includeBodyHash)';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$AuthOAuth1ModelImpl &&
(identical(other.consumerKey, consumerKey) ||
other.consumerKey == consumerKey) &&
(identical(other.consumerSecret, consumerSecret) ||
other.consumerSecret == consumerSecret) &&
(identical(other.accessToken, accessToken) ||
other.accessToken == accessToken) &&
(identical(other.tokenSecret, tokenSecret) ||
other.tokenSecret == tokenSecret) &&
(identical(other.signatureMethod, signatureMethod) ||
other.signatureMethod == signatureMethod) &&
(identical(other.parameterLocation, parameterLocation) ||
other.parameterLocation == parameterLocation) &&
(identical(other.version, version) || other.version == version) &&
(identical(other.realm, realm) || other.realm == realm) &&
(identical(other.callbackUrl, callbackUrl) ||
other.callbackUrl == callbackUrl) &&
(identical(other.verifier, verifier) ||
other.verifier == verifier) &&
(identical(other.nonce, nonce) || other.nonce == nonce) &&
(identical(other.timestamp, timestamp) ||
other.timestamp == timestamp) &&
(identical(other.includeBodyHash, includeBodyHash) ||
other.includeBodyHash == includeBodyHash));
}
@JsonKey(includeFromJson: false, includeToJson: false)
@override
int get hashCode => Object.hash(
runtimeType,
consumerKey,
consumerSecret,
accessToken,
tokenSecret,
signatureMethod,
parameterLocation,
version,
realm,
callbackUrl,
verifier,
nonce,
timestamp,
includeBodyHash,
);
/// Create a copy of AuthOAuth1Model
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@override
@pragma('vm:prefer-inline')
_$$AuthOAuth1ModelImplCopyWith<_$AuthOAuth1ModelImpl> get copyWith =>
__$$AuthOAuth1ModelImplCopyWithImpl<_$AuthOAuth1ModelImpl>(
this,
_$identity,
);
@override
Map<String, dynamic> toJson() {
return _$$AuthOAuth1ModelImplToJson(this);
}
}
abstract class _AuthOAuth1Model implements AuthOAuth1Model {
const factory _AuthOAuth1Model({
required final String consumerKey,
required final String consumerSecret,
final String? accessToken,
final String? tokenSecret,
final String signatureMethod,
final String parameterLocation,
final String version,
final String? realm,
final String? callbackUrl,
final String? verifier,
final String? nonce,
final String? timestamp,
final bool includeBodyHash,
}) = _$AuthOAuth1ModelImpl;
factory _AuthOAuth1Model.fromJson(Map<String, dynamic> json) =
_$AuthOAuth1ModelImpl.fromJson;
@override
String get consumerKey;
@override
String get consumerSecret;
@override
String? get accessToken;
@override
String? get tokenSecret;
@override
String get signatureMethod;
@override
String get parameterLocation;
@override
String get version;
@override
String? get realm;
@override
String? get callbackUrl;
@override
String? get verifier;
@override
String? get nonce;
@override
String? get timestamp;
@override
bool get includeBodyHash;
/// Create a copy of AuthOAuth1Model
/// with the given fields replaced by the non-null parameter values.
@override
@JsonKey(includeFromJson: false, includeToJson: false)
_$$AuthOAuth1ModelImplCopyWith<_$AuthOAuth1ModelImpl> get copyWith =>
throw _privateConstructorUsedError;
}

View File

@@ -0,0 +1,43 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'auth_oauth1_model.dart';
// **************************************************************************
// JsonSerializableGenerator
// **************************************************************************
_$AuthOAuth1ModelImpl _$$AuthOAuth1ModelImplFromJson(
Map<String, dynamic> json,
) => _$AuthOAuth1ModelImpl(
consumerKey: json['consumerKey'] as String,
consumerSecret: json['consumerSecret'] as String,
accessToken: json['accessToken'] as String?,
tokenSecret: json['tokenSecret'] as String?,
signatureMethod: json['signatureMethod'] as String? ?? "hmacSha1",
parameterLocation: json['parameterLocation'] as String? ?? "header",
version: json['version'] as String? ?? '1.0',
realm: json['realm'] as String?,
callbackUrl: json['callbackUrl'] as String?,
verifier: json['verifier'] as String?,
nonce: json['nonce'] as String?,
timestamp: json['timestamp'] as String?,
includeBodyHash: json['includeBodyHash'] as bool? ?? false,
);
Map<String, dynamic> _$$AuthOAuth1ModelImplToJson(
_$AuthOAuth1ModelImpl instance,
) => <String, dynamic>{
'consumerKey': instance.consumerKey,
'consumerSecret': instance.consumerSecret,
'accessToken': instance.accessToken,
'tokenSecret': instance.tokenSecret,
'signatureMethod': instance.signatureMethod,
'parameterLocation': instance.parameterLocation,
'version': instance.version,
'realm': instance.realm,
'callbackUrl': instance.callbackUrl,
'verifier': instance.verifier,
'nonce': instance.nonce,
'timestamp': instance.timestamp,
'includeBodyHash': instance.includeBodyHash,
};