Skip to content

Commit

Permalink
refactor: Update token request and use only pincode or txcode #3029
Browse files Browse the repository at this point in the history
  • Loading branch information
bibash28 committed Nov 4, 2024
1 parent b67c1cd commit c912e99
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -20,6 +21,7 @@ class Oidc4vcCredentialPickPage extends StatelessWidget {

final List<dynamic> credentials;
final String? userPin;
final String? txCode;
final String? preAuthorizedCode;
final String issuer;
final bool isEBSI;
Expand All @@ -29,6 +31,7 @@ class Oidc4vcCredentialPickPage extends StatelessWidget {
static Route<dynamic> route({
required List<dynamic> credentials,
required String? userPin,
required String? txCode,
required String? preAuthorizedCode,
required String issuer,
required bool isEBSI,
Expand All @@ -39,6 +42,7 @@ class Oidc4vcCredentialPickPage extends StatelessWidget {
builder: (context) => Oidc4vcCredentialPickPage(
credentials: credentials,
userPin: userPin,
txCode: txCode,
issuer: issuer,
preAuthorizedCode: preAuthorizedCode,
isEBSI: isEBSI,
Expand All @@ -55,6 +59,7 @@ class Oidc4vcCredentialPickPage extends StatelessWidget {
child: Oidc4vcCredentialPickView(
credentials: credentials,
userPin: userPin,
txCode: txCode,
issuer: issuer,
preAuthorizedCode: preAuthorizedCode,
isEBSI: isEBSI,
Expand All @@ -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,
Expand All @@ -79,6 +85,7 @@ class Oidc4vcCredentialPickView extends StatelessWidget {

final List<dynamic> credentials;
final String? userPin;
final String? txCode;
final String? preAuthorizedCode;
final String issuer;
final bool isEBSI;
Expand Down Expand Up @@ -203,6 +210,7 @@ class Oidc4vcCredentialPickView extends StatelessWidget {
.processSelectedCredentials(
selectedCredentials: selectedCredentials,
userPin: userPin,
txCode: txCode,
issuer: issuer,
preAuthorizedCode: preAuthorizedCode,
isEBSI: isEBSI,
Expand Down
19 changes: 18 additions & 1 deletion 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 @@ -523,7 +523,15 @@ class QRCodeScanCubit extends Cubit<QRCodeScanState> {
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,
Expand All @@ -532,6 +540,7 @@ class QRCodeScanCubit extends Cubit<QRCodeScanState> {
secureStorageProvider: getSecureStorage,
dioClient: client,
userPin: userPin,
txCode: txCodeData,
oidc4vc: oidc4vc,
isEBSI: isEBSI,
credentialOfferJson: credentialOfferJson,
Expand Down Expand Up @@ -561,6 +570,7 @@ class QRCodeScanCubit extends Cubit<QRCodeScanState> {
secureStorageProvider: getSecureStorage,
dioClient: client,
userPin: null,
txCode: null,
credentialOfferJson: credentialOfferJson,
isEBSI: isEBSI,
cryptoHolderBinding: customOidc4vcProfile.cryptoHolderBinding,
Expand Down Expand Up @@ -891,6 +901,7 @@ class QRCodeScanCubit extends Cubit<QRCodeScanState> {
void navigateToOidc4vcCredentialPickPage({
required List<dynamic> credentials,
required String? userPin,
required String? txCode,
required String? preAuthorizedCode,
required String issuer,
required bool isEBSI,
Expand All @@ -903,6 +914,7 @@ class QRCodeScanCubit extends Cubit<QRCodeScanState> {
route: Oidc4vcCredentialPickPage.route(
credentials: credentials,
userPin: userPin,
txCode: txCode,
issuer: issuer,
preAuthorizedCode: preAuthorizedCode,
isEBSI: isEBSI,
Expand Down Expand Up @@ -1260,6 +1272,7 @@ class QRCodeScanCubit extends Cubit<QRCodeScanState> {
required List<dynamic> selectedCredentials,
required bool isEBSI,
required String? userPin,
required String? txCode,
required String? preAuthorizedCode,
required String issuer,
required dynamic credentialOfferJson,
Expand All @@ -1286,6 +1299,7 @@ class QRCodeScanCubit extends Cubit<QRCodeScanState> {
selectedCredentials: selectedCredentials,
isEBSI: isEBSI,
userPin: userPin,
txCode: txCode,
preAuthorizedCode: preAuthorizedCode,
issuer: issuer,
codeForAuthorisedFlow: null,
Expand Down Expand Up @@ -1340,6 +1354,7 @@ class QRCodeScanCubit extends Cubit<QRCodeScanState> {
required List<dynamic> selectedCredentials,
required bool isEBSI,
required String? userPin,
required String? txCode,
required String? preAuthorizedCode,
required String issuer,
required String? codeForAuthorisedFlow,
Expand Down Expand Up @@ -1389,6 +1404,7 @@ class QRCodeScanCubit extends Cubit<QRCodeScanState> {
clientId: clientId,
clientSecret: clientSecret,
userPin: userPin,
txCode: txCode,
code: codeForAuthorisedFlow,
codeVerifier: codeVerifier,
authorization: authorization,
Expand Down Expand Up @@ -1596,6 +1612,7 @@ class QRCodeScanCubit extends Cubit<QRCodeScanState> {
await addCredentialsInLoop(
selectedCredentials: selectedCredentials,
userPin: null,
txCode: null,
issuer: issuer,
preAuthorizedCode: null,
isEBSI: isEBSI,
Expand Down
5 changes: 5 additions & 0 deletions lib/oidc4vc/initiate_oidv4vc_credential_issuance.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Future<void> initiateOIDC4VCCredentialIssuance({
required SecureStorageProvider secureStorageProvider,
required DioClient dioClient,
required String? userPin,
required String? txCode,
required dynamic credentialOfferJson,
required bool cryptoHolderBinding,
required OpenIdConfiguration? openIdConfiguration,
Expand Down Expand Up @@ -86,6 +87,7 @@ Future<void> initiateOIDC4VCCredentialIssuance({
qrCodeScanCubit.navigateToOidc4vcCredentialPickPage(
credentials: credentials,
userPin: userPin,
txCode: txCode,
issuer: issuer,
preAuthorizedCode: preAuthorizedCode,
isEBSI: isEBSI,
Expand All @@ -98,6 +100,7 @@ Future<void> initiateOIDC4VCCredentialIssuance({
qrCodeScanCubit.navigateToOidc4vcCredentialPickPage(
credentials: credentials,
userPin: userPin,
txCode: txCode,
issuer: issuer,
preAuthorizedCode: preAuthorizedCode,
isEBSI: isEBSI,
Expand Down Expand Up @@ -129,6 +132,7 @@ Future<void> initiateOIDC4VCCredentialIssuance({
await qrCodeScanCubit.addCredentialsInLoop(
selectedCredentials: selectedCredentials,
userPin: userPin,
txCode: txCode,
issuer: issuer,
preAuthorizedCode: null,
isEBSI: isEBSI,
Expand All @@ -147,6 +151,7 @@ Future<void> initiateOIDC4VCCredentialIssuance({
// full phase flow of preAuthorized
await qrCodeScanCubit.processSelectedCredentials(
userPin: userPin,
txCode: txCode,
issuer: issuer,
preAuthorizedCode: preAuthorizedCode,
isEBSI: isEBSI,
Expand Down
11 changes: 8 additions & 3 deletions packages/oidc4vc/lib/src/oidc4vc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -615,6 +616,7 @@ class OIDC4VC {
code: code,
codeVerifier: codeVerifier,
clientId: clientId,
txCode: txCode,
clientSecret: clientSecret,
authorization: authorization,
redirectUri: redirectUri,
Expand Down Expand Up @@ -771,6 +773,7 @@ class OIDC4VC {
required String redirectUri,
String? preAuthorizedCode,
String? userPin,
String? txCode,
String? code,
String? codeVerifier,
String? clientId,
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit c912e99

Please sign in to comment.