feat: add oauth2 ui and authorzation code grant handling

This commit is contained in:
Udhay-Adithya
2025-07-20 23:07:58 +05:30
parent 4453ac1b2a
commit fd4b05663c
13 changed files with 1039 additions and 15 deletions

View File

@@ -1,3 +1,4 @@
import 'package:better_networking/consts.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
part 'auth_oauth2_model.g.dart';
@@ -7,7 +8,7 @@ part 'auth_oauth2_model.freezed.dart';
@freezed
class AuthOAuth2Model with _$AuthOAuth2Model {
const factory AuthOAuth2Model({
@Default("authorization_code") String grantType,
@Default(OAuth2GrantType.authorizationCode) OAuth2GrantType grantType,
required String authorizationUrl,

View File

@@ -21,7 +21,7 @@ AuthOAuth2Model _$AuthOAuth2ModelFromJson(Map<String, dynamic> json) {
/// @nodoc
mixin _$AuthOAuth2Model {
String get grantType => throw _privateConstructorUsedError;
OAuth2GrantType get grantType => throw _privateConstructorUsedError;
String get authorizationUrl => throw _privateConstructorUsedError;
String get accessTokenUrl => throw _privateConstructorUsedError;
String get clientId => throw _privateConstructorUsedError;
@@ -56,7 +56,7 @@ abstract class $AuthOAuth2ModelCopyWith<$Res> {
) = _$AuthOAuth2ModelCopyWithImpl<$Res, AuthOAuth2Model>;
@useResult
$Res call({
String grantType,
OAuth2GrantType grantType,
String authorizationUrl,
String accessTokenUrl,
String clientId,
@@ -112,7 +112,7 @@ class _$AuthOAuth2ModelCopyWithImpl<$Res, $Val extends AuthOAuth2Model>
grantType: null == grantType
? _value.grantType
: grantType // ignore: cast_nullable_to_non_nullable
as String,
as OAuth2GrantType,
authorizationUrl: null == authorizationUrl
? _value.authorizationUrl
: authorizationUrl // ignore: cast_nullable_to_non_nullable
@@ -189,7 +189,7 @@ abstract class _$$AuthOAuth2ModelImplCopyWith<$Res>
@override
@useResult
$Res call({
String grantType,
OAuth2GrantType grantType,
String authorizationUrl,
String accessTokenUrl,
String clientId,
@@ -244,7 +244,7 @@ class __$$AuthOAuth2ModelImplCopyWithImpl<$Res>
grantType: null == grantType
? _value.grantType
: grantType // ignore: cast_nullable_to_non_nullable
as String,
as OAuth2GrantType,
authorizationUrl: null == authorizationUrl
? _value.authorizationUrl
: authorizationUrl // ignore: cast_nullable_to_non_nullable
@@ -314,7 +314,7 @@ class __$$AuthOAuth2ModelImplCopyWithImpl<$Res>
@JsonSerializable()
class _$AuthOAuth2ModelImpl implements _AuthOAuth2Model {
const _$AuthOAuth2ModelImpl({
this.grantType = "authorization_code",
this.grantType = OAuth2GrantType.authorizationCode,
required this.authorizationUrl,
required this.accessTokenUrl,
required this.clientId,
@@ -337,7 +337,7 @@ class _$AuthOAuth2ModelImpl implements _AuthOAuth2Model {
@override
@JsonKey()
final String grantType;
final OAuth2GrantType grantType;
@override
final String authorizationUrl;
@override
@@ -453,7 +453,7 @@ class _$AuthOAuth2ModelImpl implements _AuthOAuth2Model {
abstract class _AuthOAuth2Model implements AuthOAuth2Model {
const factory _AuthOAuth2Model({
final String grantType,
final OAuth2GrantType grantType,
required final String authorizationUrl,
required final String accessTokenUrl,
required final String clientId,
@@ -475,7 +475,7 @@ abstract class _AuthOAuth2Model implements AuthOAuth2Model {
_$AuthOAuth2ModelImpl.fromJson;
@override
String get grantType;
OAuth2GrantType get grantType;
@override
String get authorizationUrl;
@override

View File

@@ -9,7 +9,9 @@ part of 'auth_oauth2_model.dart';
_$AuthOAuth2ModelImpl _$$AuthOAuth2ModelImplFromJson(
Map<String, dynamic> json,
) => _$AuthOAuth2ModelImpl(
grantType: json['grantType'] as String? ?? "authorization_code",
grantType:
$enumDecodeNullable(_$OAuth2GrantTypeEnumMap, json['grantType']) ??
OAuth2GrantType.authorizationCode,
authorizationUrl: json['authorizationUrl'] as String,
accessTokenUrl: json['accessTokenUrl'] as String,
clientId: json['clientId'] as String,
@@ -30,7 +32,7 @@ _$AuthOAuth2ModelImpl _$$AuthOAuth2ModelImplFromJson(
Map<String, dynamic> _$$AuthOAuth2ModelImplToJson(
_$AuthOAuth2ModelImpl instance,
) => <String, dynamic>{
'grantType': instance.grantType,
'grantType': _$OAuth2GrantTypeEnumMap[instance.grantType]!,
'authorizationUrl': instance.authorizationUrl,
'accessTokenUrl': instance.accessTokenUrl,
'clientId': instance.clientId,
@@ -47,3 +49,9 @@ Map<String, dynamic> _$$AuthOAuth2ModelImplToJson(
'identityToken': instance.identityToken,
'accessToken': instance.accessToken,
};
const _$OAuth2GrantTypeEnumMap = {
OAuth2GrantType.authorizationCode: 'authorizationCode',
OAuth2GrantType.clientCredentials: 'clientCredentials',
OAuth2GrantType.resourceOwnerPassword: 'resourceOwnerPassword',
};