Skip to content

Commit

Permalink
feat: Show token data and credential data to be sent #3054
Browse files Browse the repository at this point in the history
  • Loading branch information
bibash28 committed Nov 6, 2024
1 parent 96a1573 commit 0b74940
Show file tree
Hide file tree
Showing 8 changed files with 341 additions and 319 deletions.
1 change: 1 addition & 0 deletions lib/app/shared/enum/status/qr_scan_status.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ enum QrScanStatus {
success,
goBack,
pauseForDialog,
pauseForDisplay,
}
27 changes: 26 additions & 1 deletion lib/dashboard/json_viewer/view/json_viewer_page.dart
Original file line number Diff line number Diff line change
@@ -1,25 +1,30 @@
import 'package:altme/app/app.dart';
import 'package:altme/dashboard/dashboard.dart';
import 'package:altme/l10n/l10n.dart';
import 'package:flutter/material.dart';

class JsonViewerPage extends StatelessWidget {
const JsonViewerPage({
super.key,
required this.title,
required this.data,
required this.showContinueButton,
});

final String title;
final String data;
final bool showContinueButton;

static Route<dynamic> route({
required String title,
required String data,
bool showContinueButton = false,
}) =>
MaterialPageRoute<void>(
builder: (_) => JsonViewerPage(
title: title,
data: data,
showContinueButton: showContinueButton,
),
settings: const RouteSettings(name: '/JsonViewerPage'),
);
Expand All @@ -29,6 +34,7 @@ class JsonViewerPage extends StatelessWidget {
return JsonViewerView(
title: title,
data: data,
showContinueButton: showContinueButton,
);
}
}
Expand All @@ -38,20 +44,39 @@ class JsonViewerView extends StatelessWidget {
super.key,
required this.title,
required this.data,
required this.showContinueButton,
});

final String title;
final String data;
final bool showContinueButton;

@override
Widget build(BuildContext context) {
return BasePage(
title: title,
titleAlignment: Alignment.topCenter,
scrollView: true,
titleLeading: const BackLeadingButton(),
titleLeading: BackLeadingButton(
onPressed: () {
Navigator.of(context).pop(false);
},
),
padding: const EdgeInsets.symmetric(horizontal: 10),
body: JsonViewWidget(data: data),
navigation: !showContinueButton
? null
: Padding(
padding: const EdgeInsets.all(
Sizes.spaceSmall,
),
child: MyElevatedButton(
text: context.l10n.continueString,
onPressed: () {
Navigator.of(context).pop(true);
},
),
),
);
}
}
82 changes: 66 additions & 16 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 @@ -1392,31 +1392,54 @@ class QRCodeScanCubit extends Cubit<QRCodeScanState> {
);

if (savedAccessToken == null) {
/// get tokendata
final tokenData = oidc4vc.buildTokenData(
preAuthorizedCode: preAuthorizedCode,
userPin: userPin,
code: codeForAuthorisedFlow,
codeVerifier: codeVerifier,
clientId: clientId,
txCode: txCode,
clientSecret: clientSecret,
authorization: authorization,
redirectUri: Parameters.oidc4vcUniversalLink,
oAuthClientAttestation: oAuthClientAttestation,
oAuthClientAttestationPop: oAuthClientAttestationPop,
);

if (profileCubit.state.model.isDeveloperMode) {
final value = await showDataBeforeSending(
title: 'TOKEN DATA',
data: tokenData,
);
if (value) {
completer = null;
} else {
completer = null;
resetNonceAndAccessTokenAndAuthorizationDetails();
goBack();
return;
}
}

/// get token response
final (
Map<String, dynamic>? tokenResponse,
String? accessToken,
String? cnonce,
List<dynamic>? authorizationDetails,
) = await oidc4vc.getTokenResponse(
preAuthorizedCode: preAuthorizedCode,
issuer: issuer,
clientId: clientId,
clientSecret: clientSecret,
userPin: userPin,
txCode: txCode,
code: codeForAuthorisedFlow,
codeVerifier: codeVerifier,
authorization: authorization,
oidc4vciDraftType: customOidc4vcProfile.oidc4vciDraft,
redirectUri: Parameters.oidc4vcUniversalLink,
openIdConfiguration:
OpenIdConfiguration.fromJson(openIdConfigurationData),
oAuthClientAttestation: oAuthClientAttestation,
oAuthClientAttestationPop: oAuthClientAttestationPop,
dio: client.dio,
useOAuthAuthorizationServerLink:
useOauthServerAuthEndPoint(profileCubit.state.model),
tokenData: tokenData,
);

savedAccessToken = accessToken;
Expand Down Expand Up @@ -1458,11 +1481,7 @@ class QRCodeScanCubit extends Cubit<QRCodeScanState> {
}

/// get credentials
final (
List<dynamic> encodedCredentialOrFutureTokens,
String? deferredCredentialEndpoint,
String format,
) = await getCredential(
final result = await getCredential(
isEBSI: isEBSI,
credential: selectedCredentials[i],
issuer: issuer,
Expand All @@ -1472,13 +1491,22 @@ class QRCodeScanCubit extends Cubit<QRCodeScanState> {
clientId: clientId,
profileCubit: profileCubit,
accessToken: savedAccessToken!,
nonce: savedNonce,
cnonce: savedNonce,
authorizationDetails: savedAuthorizationDetails,
openIdConfiguration:
OpenIdConfiguration.fromJson(openIdConfigurationData),
qrCodeScanCubit: qrCodeScanCubit,
);

final lastElement = encodedCredentialOrFutureTokens.last;
if (result == null) return;

final (
encodedCredentialOrFutureTokens,
deferredCredentialEndpoint,
format
) = result;

final lastElement = encodedCredentialOrFutureTokens!.last;

/// update nonce value
if (lastElement is Map<String, dynamic>) {
Expand Down Expand Up @@ -1525,7 +1553,7 @@ class QRCodeScanCubit extends Cubit<QRCodeScanState> {
blockchainType: walletCubit.state.currentAccount!.blockchainType,
deferredCredentialEndpoint: deferredCredentialEndpoint,
encodedCredentialOrFutureTokens: encodedCredentialOrFutureTokens,
format: format,
format: format!,
openIdConfiguration:
OpenIdConfiguration.fromJson(openIdConfigurationData),
qrCodeScanCubit: qrCodeScanCubit,
Expand All @@ -1549,6 +1577,28 @@ class QRCodeScanCubit extends Cubit<QRCodeScanState> {
}
}

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

final formattedData = '''
<b>$title :</b>
${const JsonEncoder.withIndent(' ').convert(data)}\n
''';
emit(
state.copyWith(
qrScanStatus: QrScanStatus.pauseForDisplay,
dialogData: formattedData,
),
);

final value = await completer!.future;

return value;
}

void resetNonceAndAccessTokenAndAuthorizationDetails() {
savedAccessToken = null;
savedNonce = null;
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 0b74940

Please sign in to comment.