feat: enhance authentication fields with additional info

This commit is contained in:
Udhay-Adithya
2025-07-07 22:25:54 +05:30
parent 739afca856
commit e838654b2d
4 changed files with 59 additions and 29 deletions

View File

@@ -75,7 +75,8 @@ class _ApiKeyAuthFieldsState extends State<ApiKeyAuthFields> {
AuthTextField( AuthTextField(
readOnly: widget.readOnly, readOnly: widget.readOnly,
controller: _keyController, controller: _keyController,
hintText: "API Key", title: "API Key",
hintText: "Key",
isObscureText: true, isObscureText: true,
onChanged: (value) => _updateApiKeyAuth(), onChanged: (value) => _updateApiKeyAuth(),
), ),
@@ -84,22 +85,21 @@ class _ApiKeyAuthFieldsState extends State<ApiKeyAuthFields> {
} }
void _updateApiKeyAuth() { void _updateApiKeyAuth() {
widget.updateAuth( widget.updateAuth(widget.authData?.copyWith(
widget.authData?.copyWith(
type: APIAuthType.apiKey, type: APIAuthType.apiKey,
apikey: AuthApiKeyModel( apikey: AuthApiKeyModel(
key: _keyController.text.trim(), key: _keyController.text.trim(),
name: _nameController.text.trim(), name: _nameController.text.trim(),
location: _addKeyTo, location: _addKeyTo,
), ),
) ?? AuthModel( ) ??
AuthModel(
type: APIAuthType.apiKey, type: APIAuthType.apiKey,
apikey: AuthApiKeyModel( apikey: AuthApiKeyModel(
key: _keyController.text.trim(), key: _keyController.text.trim(),
name: _nameController.text.trim(), name: _nameController.text.trim(),
location: _addKeyTo, location: _addKeyTo,
), ),
) ));
);
} }
} }

View File

@@ -51,6 +51,8 @@ class _DigestAuthFieldsState extends State<DigestAuthFields> {
readOnly: widget.readOnly, readOnly: widget.readOnly,
controller: _usernameController, controller: _usernameController,
hintText: "Username", hintText: "Username",
infoText:
"Your username for digest authentication. This will be sent to the server for credential verification.",
onChanged: (_) => _updateDigestAuth(), onChanged: (_) => _updateDigestAuth(),
), ),
const SizedBox(height: 12), const SizedBox(height: 12),
@@ -59,6 +61,8 @@ class _DigestAuthFieldsState extends State<DigestAuthFields> {
controller: _passwordController, controller: _passwordController,
hintText: "Password", hintText: "Password",
isObscureText: true, isObscureText: true,
infoText:
"Your password for digest authentication. This is hashed and not sent in plain text to the server.",
onChanged: (_) => _updateDigestAuth(), onChanged: (_) => _updateDigestAuth(),
), ),
const SizedBox(height: 12), const SizedBox(height: 12),
@@ -66,6 +70,8 @@ class _DigestAuthFieldsState extends State<DigestAuthFields> {
readOnly: widget.readOnly, readOnly: widget.readOnly,
controller: _realmController, controller: _realmController,
hintText: "Realm", hintText: "Realm",
infoText:
"Authentication realm as specified by the server. This defines the protection space for the credentials.",
onChanged: (_) => _updateDigestAuth(), onChanged: (_) => _updateDigestAuth(),
), ),
const SizedBox(height: 12), const SizedBox(height: 12),
@@ -73,6 +79,8 @@ class _DigestAuthFieldsState extends State<DigestAuthFields> {
readOnly: widget.readOnly, readOnly: widget.readOnly,
controller: _nonceController, controller: _nonceController,
hintText: "Nonce", hintText: "Nonce",
infoText:
"Server-generated random value used to prevent replay attacks.",
onChanged: (_) => _updateDigestAuth(), onChanged: (_) => _updateDigestAuth(),
), ),
const SizedBox(height: 12), const SizedBox(height: 12),
@@ -92,7 +100,7 @@ class _DigestAuthFieldsState extends State<DigestAuthFields> {
('SHA-256', 'SHA-256'), ('SHA-256', 'SHA-256'),
('SHA-256-sess', 'SHA-256-sess'), ('SHA-256-sess', 'SHA-256-sess'),
], ],
tooltip: "this algorithm will be used to produce the digest", tooltip: "Algorithm that will be used to produce the digest",
isOutlined: true, isOutlined: true,
onChanged: (String? newLocation) { onChanged: (String? newLocation) {
if (newLocation != null) { if (newLocation != null) {
@@ -107,7 +115,9 @@ class _DigestAuthFieldsState extends State<DigestAuthFields> {
AuthTextField( AuthTextField(
readOnly: widget.readOnly, readOnly: widget.readOnly,
controller: _qopController, controller: _qopController,
hintText: "QOP (e.g. auth)", hintText: "QOP",
infoText:
"Quality of Protection. Typically 'auth' for authentication only, or 'auth-int' for authentication with integrity protection.",
onChanged: (_) => _updateDigestAuth(), onChanged: (_) => _updateDigestAuth(),
), ),
const SizedBox(height: 12), const SizedBox(height: 12),
@@ -115,6 +125,8 @@ class _DigestAuthFieldsState extends State<DigestAuthFields> {
readOnly: widget.readOnly, readOnly: widget.readOnly,
controller: _opaqueController, controller: _opaqueController,
hintText: "Opaque", hintText: "Opaque",
infoText:
"Server-specified data string that should be returned unchanged in the authorization header. Usually obtained from server's 401 response.",
onChanged: (_) => _updateDigestAuth(), onChanged: (_) => _updateDigestAuth(),
), ),
], ],

View File

@@ -115,6 +115,8 @@ class _JwtAuthFieldsState extends State<JwtAuthFields> {
controller: _secretController, controller: _secretController,
isObscureText: true, isObscureText: true,
hintText: "Secret key", hintText: "Secret key",
infoText:
"The secret key used to sign the JWT token. Keep this secure and match it with your server configuration.",
onChanged: (value) => _updateJwtAuth(), onChanged: (value) => _updateJwtAuth(),
), ),
const SizedBox(height: 16), const SizedBox(height: 16),
@@ -139,7 +141,7 @@ class _JwtAuthFieldsState extends State<JwtAuthFields> {
), ),
] else ...[ ] else ...[
Text( Text(
"Private Key (PEM Format)", "Private Key",
style: TextStyle( style: TextStyle(
fontWeight: FontWeight.normal, fontWeight: FontWeight.normal,
fontSize: 14, fontSize: 14,

View File

@@ -4,19 +4,22 @@ import 'package:flutter/material.dart';
class AuthTextField extends StatefulWidget { class AuthTextField extends StatefulWidget {
final String hintText; final String hintText;
final String? title;
final TextEditingController controller; final TextEditingController controller;
final bool isObscureText; final bool isObscureText;
final Function(String)? onChanged; final Function(String)? onChanged;
final bool readOnly; final bool readOnly;
final String? infoText;
const AuthTextField({ const AuthTextField(
super.key, {super.key,
this.title,
required this.hintText, required this.hintText,
required this.controller, required this.controller,
required this.onChanged, required this.onChanged,
this.readOnly = false, this.readOnly = false,
this.isObscureText = false, this.isObscureText = false,
}); this.infoText});
@override @override
State<AuthTextField> createState() => _AuthFieldState(); State<AuthTextField> createState() => _AuthFieldState();
@@ -44,13 +47,26 @@ class _AuthFieldState extends State<AuthTextField> {
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
Text( Row(
widget.hintText, mainAxisAlignment: MainAxisAlignment.start,
style: TextStyle( children: [
fontWeight: FontWeight.normal, Text(widget.title ?? widget.hintText),
fontSize: 14, if (widget.infoText != null)
Tooltip(
message: widget.infoText!,
triggerMode: TooltipTriggerMode.tap,
showDuration: Duration(seconds: 5),
child: Padding(
padding: const EdgeInsets.only(left: 4.0),
child: Icon(
Icons.help_outline_rounded,
color: Theme.of(context).colorScheme.secondary,
size: 18,
), ),
), ),
),
],
),
const SizedBox(height: 6), const SizedBox(height: 6),
TextFormField( TextFormField(
readOnly: widget.readOnly, readOnly: widget.readOnly,