Skip to content

Commit

Permalink
feat: Add authorization response from callback #3076
Browse files Browse the repository at this point in the history
  • Loading branch information
bibash28 committed Nov 12, 2024
1 parent 75e84c2 commit eb60848
Showing 1 changed file with 58 additions and 30 deletions.
88 changes: 58 additions & 30 deletions lib/dashboard/qr_code/qr_code_scan/cubit/qr_code_scan_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1609,67 +1609,75 @@ class QRCodeScanCubit extends Cubit<QRCodeScanState> {
}

Future<bool> showDataBeforeSending({
required String title,
required Map<String, dynamic> data,
String? title,
Map<String, dynamic>? data,
String? fullData,
}) async {
completer = Completer<bool>();

var formattedData = '''
var formattedData = '';

if (fullData != null) {
formattedData = fullData;
} else {
formattedData = '''
<b>$title :</b>
${const JsonEncoder.withIndent(' ').convert(data)}
''';

/// jwt
final jwtMappedIterable = JsonPath(r'$..jwt').read(data);
/// jwt
final jwtMappedIterable = JsonPath(r'$..jwt').read(data);

if (jwtMappedIterable.isNotEmpty) {
final jwtValue = jwtMappedIterable.first.value;
if (jwtMappedIterable.isNotEmpty) {
final jwtValue = jwtMappedIterable.first.value;

if (jwtValue != null) {
final jwt = jwtValue.toString();
if (jwtValue != null) {
final jwt = jwtValue.toString();

try {
final header = jwtDecode.parseJwtHeader(jwt);
final payload = jwtDecode.parseJwt(jwt);
try {
final header = jwtDecode.parseJwtHeader(jwt);
final payload = jwtDecode.parseJwt(jwt);

final jwtData = '''
final jwtData = '''
<b>HEADER :</b>
${const JsonEncoder.withIndent(' ').convert(header)}\n
<b>PAYLOAD :</b>
${const JsonEncoder.withIndent(' ').convert(payload)}
''';
formattedData = '$formattedData\n$jwtData';
} catch (e) {
//
formattedData = '$formattedData\n$jwtData';
} catch (e) {
//
}
}
}
}

/// id_token
final idTokenMappedIterable = JsonPath(r'$..id_token').read(data);
/// id_token
final idTokenMappedIterable = JsonPath(r'$..id_token').read(data);

if (idTokenMappedIterable.isNotEmpty) {
final jwtValue = idTokenMappedIterable.first.value;
if (idTokenMappedIterable.isNotEmpty) {
final jwtValue = idTokenMappedIterable.first.value;

if (jwtValue != null) {
final jwt = jwtValue.toString();
if (jwtValue != null) {
final jwt = jwtValue.toString();

try {
final header = jwtDecode.parseJwtHeader(jwt);
final payload = jwtDecode.parseJwt(jwt);
try {
final header = jwtDecode.parseJwtHeader(jwt);
final payload = jwtDecode.parseJwt(jwt);

final jwtData = '''
final jwtData = '''
<b>HEADER :</b>
${const JsonEncoder.withIndent(' ').convert(header)}\n
<b>PAYLOAD :</b>
${const JsonEncoder.withIndent(' ').convert(payload)}
''';
formattedData = '$formattedData\n$jwtData';
} catch (e) {
//
formattedData = '$formattedData\n$jwtData';
} catch (e) {
//
}
}
}
}

emit(
state.copyWith(
qrScanStatus: QrScanStatus.pauseForDisplay,
Expand Down Expand Up @@ -1730,6 +1738,26 @@ ${const JsonEncoder.withIndent(' ').convert(payload)}
);
}

if (profileCubit.state.model.isDeveloperMode) {
final formattedData = '''
<b>AUTHORIZATION RESPONSE:</b>
${state.uri}
''';

final value = await qrCodeScanCubit.showDataBeforeSending(
fullData: formattedData,
);

if (value) {
qrCodeScanCubit.completer = null;
} else {
qrCodeScanCubit.completer = null;
qrCodeScanCubit.resetNonceAndAccessTokenAndAuthorizationDetails();
qrCodeScanCubit.goBack();
return;
}
}

final selectedCredentials = statePayload['credentials'] as List<dynamic>;
final String codeVerifier = statePayload['codeVerifier'].toString();
final String issuer = statePayload['issuer'].toString();
Expand Down

0 comments on commit eb60848

Please sign in to comment.