From c912e99b08491a8f80e4dbaed8796f76320fb856 Mon Sep 17 00:00:00 2001 From: Bibash Shrestha Date: Mon, 4 Nov 2024 14:54:50 +0545 Subject: [PATCH] refactor: Update token request and use only pincode or txcode #3029 --- .../view/oid4c4vc_credential_pick_page.dart | 8 ++++++++ .../cubit/qr_code_scan_cubit.dart | 19 ++++++++++++++++++- .../initiate_oidv4vc_credential_issuance.dart | 5 +++++ packages/oidc4vc/lib/src/oidc4vc.dart | 11 ++++++++--- 4 files changed, 39 insertions(+), 4 deletions(-) diff --git a/lib/dashboard/home/tab_bar/credentials/oid4c4vc_pick/oid4c4vc_credential_pick/view/oid4c4vc_credential_pick_page.dart b/lib/dashboard/home/tab_bar/credentials/oid4c4vc_pick/oid4c4vc_credential_pick/view/oid4c4vc_credential_pick_page.dart index fff935853..cdf495ae7 100644 --- a/lib/dashboard/home/tab_bar/credentials/oid4c4vc_pick/oid4c4vc_credential_pick/view/oid4c4vc_credential_pick_page.dart +++ b/lib/dashboard/home/tab_bar/credentials/oid4c4vc_pick/oid4c4vc_credential_pick/view/oid4c4vc_credential_pick_page.dart @@ -11,6 +11,7 @@ class Oidc4vcCredentialPickPage extends StatelessWidget { super.key, required this.credentials, required this.userPin, + required this.txCode, required this.preAuthorizedCode, required this.issuer, required this.isEBSI, @@ -20,6 +21,7 @@ class Oidc4vcCredentialPickPage extends StatelessWidget { final List credentials; final String? userPin; + final String? txCode; final String? preAuthorizedCode; final String issuer; final bool isEBSI; @@ -29,6 +31,7 @@ class Oidc4vcCredentialPickPage extends StatelessWidget { static Route route({ required List credentials, required String? userPin, + required String? txCode, required String? preAuthorizedCode, required String issuer, required bool isEBSI, @@ -39,6 +42,7 @@ class Oidc4vcCredentialPickPage extends StatelessWidget { builder: (context) => Oidc4vcCredentialPickPage( credentials: credentials, userPin: userPin, + txCode: txCode, issuer: issuer, preAuthorizedCode: preAuthorizedCode, isEBSI: isEBSI, @@ -55,6 +59,7 @@ class Oidc4vcCredentialPickPage extends StatelessWidget { child: Oidc4vcCredentialPickView( credentials: credentials, userPin: userPin, + txCode: txCode, issuer: issuer, preAuthorizedCode: preAuthorizedCode, isEBSI: isEBSI, @@ -70,6 +75,7 @@ class Oidc4vcCredentialPickView extends StatelessWidget { super.key, required this.credentials, required this.userPin, + required this.txCode, required this.preAuthorizedCode, required this.issuer, required this.isEBSI, @@ -79,6 +85,7 @@ class Oidc4vcCredentialPickView extends StatelessWidget { final List credentials; final String? userPin; + final String? txCode; final String? preAuthorizedCode; final String issuer; final bool isEBSI; @@ -203,6 +210,7 @@ class Oidc4vcCredentialPickView extends StatelessWidget { .processSelectedCredentials( selectedCredentials: selectedCredentials, userPin: userPin, + txCode: txCode, issuer: issuer, preAuthorizedCode: preAuthorizedCode, isEBSI: isEBSI, diff --git a/lib/dashboard/qr_code/qr_code_scan/cubit/qr_code_scan_cubit.dart b/lib/dashboard/qr_code/qr_code_scan/cubit/qr_code_scan_cubit.dart index b89b838ae..5f3a8d2a7 100644 --- a/lib/dashboard/qr_code/qr_code_scan/cubit/qr_code_scan_cubit.dart +++ b/lib/dashboard/qr_code/qr_code_scan/cubit/qr_code_scan_cubit.dart @@ -523,7 +523,15 @@ class QRCodeScanCubit extends Cubit { onCancel: () { goBack(); }, - onProceed: (String userPin) async { + onProceed: (String pinCode) async { + String? userPin; + String? txCodeData; + + if (txCode != null) { + txCodeData = pinCode; + } else { + userPin = pinCode; + } await initiateOIDC4VCCredentialIssuance( scannedResponse: scannedResponse, credentialsCubit: credentialsCubit, @@ -532,6 +540,7 @@ class QRCodeScanCubit extends Cubit { secureStorageProvider: getSecureStorage, dioClient: client, userPin: userPin, + txCode: txCodeData, oidc4vc: oidc4vc, isEBSI: isEBSI, credentialOfferJson: credentialOfferJson, @@ -561,6 +570,7 @@ class QRCodeScanCubit extends Cubit { secureStorageProvider: getSecureStorage, dioClient: client, userPin: null, + txCode: null, credentialOfferJson: credentialOfferJson, isEBSI: isEBSI, cryptoHolderBinding: customOidc4vcProfile.cryptoHolderBinding, @@ -891,6 +901,7 @@ class QRCodeScanCubit extends Cubit { void navigateToOidc4vcCredentialPickPage({ required List credentials, required String? userPin, + required String? txCode, required String? preAuthorizedCode, required String issuer, required bool isEBSI, @@ -903,6 +914,7 @@ class QRCodeScanCubit extends Cubit { route: Oidc4vcCredentialPickPage.route( credentials: credentials, userPin: userPin, + txCode: txCode, issuer: issuer, preAuthorizedCode: preAuthorizedCode, isEBSI: isEBSI, @@ -1260,6 +1272,7 @@ class QRCodeScanCubit extends Cubit { required List selectedCredentials, required bool isEBSI, required String? userPin, + required String? txCode, required String? preAuthorizedCode, required String issuer, required dynamic credentialOfferJson, @@ -1286,6 +1299,7 @@ class QRCodeScanCubit extends Cubit { selectedCredentials: selectedCredentials, isEBSI: isEBSI, userPin: userPin, + txCode: txCode, preAuthorizedCode: preAuthorizedCode, issuer: issuer, codeForAuthorisedFlow: null, @@ -1340,6 +1354,7 @@ class QRCodeScanCubit extends Cubit { required List selectedCredentials, required bool isEBSI, required String? userPin, + required String? txCode, required String? preAuthorizedCode, required String issuer, required String? codeForAuthorisedFlow, @@ -1389,6 +1404,7 @@ class QRCodeScanCubit extends Cubit { clientId: clientId, clientSecret: clientSecret, userPin: userPin, + txCode: txCode, code: codeForAuthorisedFlow, codeVerifier: codeVerifier, authorization: authorization, @@ -1596,6 +1612,7 @@ class QRCodeScanCubit extends Cubit { await addCredentialsInLoop( selectedCredentials: selectedCredentials, userPin: null, + txCode: null, issuer: issuer, preAuthorizedCode: null, isEBSI: isEBSI, diff --git a/lib/oidc4vc/initiate_oidv4vc_credential_issuance.dart b/lib/oidc4vc/initiate_oidv4vc_credential_issuance.dart index 724703770..e393ed419 100644 --- a/lib/oidc4vc/initiate_oidv4vc_credential_issuance.dart +++ b/lib/oidc4vc/initiate_oidv4vc_credential_issuance.dart @@ -20,6 +20,7 @@ Future initiateOIDC4VCCredentialIssuance({ required SecureStorageProvider secureStorageProvider, required DioClient dioClient, required String? userPin, + required String? txCode, required dynamic credentialOfferJson, required bool cryptoHolderBinding, required OpenIdConfiguration? openIdConfiguration, @@ -86,6 +87,7 @@ Future initiateOIDC4VCCredentialIssuance({ qrCodeScanCubit.navigateToOidc4vcCredentialPickPage( credentials: credentials, userPin: userPin, + txCode: txCode, issuer: issuer, preAuthorizedCode: preAuthorizedCode, isEBSI: isEBSI, @@ -98,6 +100,7 @@ Future initiateOIDC4VCCredentialIssuance({ qrCodeScanCubit.navigateToOidc4vcCredentialPickPage( credentials: credentials, userPin: userPin, + txCode: txCode, issuer: issuer, preAuthorizedCode: preAuthorizedCode, isEBSI: isEBSI, @@ -129,6 +132,7 @@ Future initiateOIDC4VCCredentialIssuance({ await qrCodeScanCubit.addCredentialsInLoop( selectedCredentials: selectedCredentials, userPin: userPin, + txCode: txCode, issuer: issuer, preAuthorizedCode: null, isEBSI: isEBSI, @@ -147,6 +151,7 @@ Future initiateOIDC4VCCredentialIssuance({ // full phase flow of preAuthorized await qrCodeScanCubit.processSelectedCredentials( userPin: userPin, + txCode: txCode, issuer: issuer, preAuthorizedCode: preAuthorizedCode, isEBSI: isEBSI, diff --git a/packages/oidc4vc/lib/src/oidc4vc.dart b/packages/oidc4vc/lib/src/oidc4vc.dart index 7a8856f4f..c2958b247 100644 --- a/packages/oidc4vc/lib/src/oidc4vc.dart +++ b/packages/oidc4vc/lib/src/oidc4vc.dart @@ -588,8 +588,9 @@ class OIDC4VC { required OpenIdConfiguration openIdConfiguration, required Dio dio, required bool useOAuthAuthorizationServerLink, + required String? userPin, + required String? txCode, String? preAuthorizedCode, - String? userPin, String? code, String? codeVerifier, String? authorization, @@ -615,6 +616,7 @@ class OIDC4VC { code: code, codeVerifier: codeVerifier, clientId: clientId, + txCode: txCode, clientSecret: clientSecret, authorization: authorization, redirectUri: redirectUri, @@ -771,6 +773,7 @@ class OIDC4VC { required String redirectUri, String? preAuthorizedCode, String? userPin, + String? txCode, String? code, String? codeVerifier, String? clientId, @@ -808,9 +811,11 @@ class OIDC4VC { if (userPin != null) { tokenData['user_pin'] = userPin; + } - /// draft 13 - tokenData['tx_code'] = userPin; + /// draft 13 and above + if (txCode != null) { + tokenData['tx_code'] = txCode; } return tokenData;