Skip to content

Commit

Permalink
feat: EBSIV3 compliance test completion #1946
Browse files Browse the repository at this point in the history
  • Loading branch information
bibash28 committed Oct 16, 2023
1 parent 315ab9f commit df6ca9d
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 10 deletions.
1 change: 1 addition & 0 deletions lib/app/shared/enum/status/scan_status.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ enum ScanStatus {
error,
warning,
success,
goBack,
}
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ class CredentialManifestOfferPickView extends StatelessWidget {
keyId: SecureStorageKeys.ssiKey,
credentialsToBePresented: updatedCredentials,
issuer: issuer,
qrCodeScanCubit: context.read<QRCodeScanCubit>(),
);
}
}
Expand Down
59 changes: 49 additions & 10 deletions lib/scan/cubit/scan_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class ScanCubit extends Cubit<ScanState> {
required String keyId,
required List<CredentialModel>? credentialsToBePresented,
required Issuer issuer,
QRCodeScanCubit? qrCodeScanCubit,
}) async {
emit(state.loading());
await Future<void>.delayed(const Duration(milliseconds: 500));
Expand Down Expand Up @@ -99,6 +100,7 @@ class ScanCubit extends Cubit<ScanState> {
privateKey: privateKey,
stateValue: stateValue,
idTokenNeeded: false,
qrCodeScanCubit: qrCodeScanCubit!,
);
return;
} else if (isIDTokenAndVPToken(responseType)) {
Expand All @@ -116,6 +118,7 @@ class ScanCubit extends Cubit<ScanState> {
privateKey: privateKey,
stateValue: stateValue,
idTokenNeeded: true,
qrCodeScanCubit: qrCodeScanCubit!,
);

return;
Expand Down Expand Up @@ -451,6 +454,7 @@ class ScanCubit extends Cubit<ScanState> {
required Uri uri,
required String? stateValue,
required bool idTokenNeeded,
required QRCodeScanCubit qrCodeScanCubit,
}) async {
final log =
getLogger('ScanCubit - presentCredentialToOIDC4VPAndSIOPV2Request');
Expand Down Expand Up @@ -503,17 +507,21 @@ class ScanCubit extends Cubit<ScanState> {
responseData['state'] = stateValue;
}

final formData = FormData.fromMap(responseData);

final result = await client.post(
final response = await client.dio.post<dynamic>(
responseOrRedirectUri,
data: formData,
headers: <String, dynamic>{
'Content-Type': 'application/x-www-form-urlencoded',
},
data: responseData,
options: Options(
headers: <String, dynamic>{
'Content-Type': 'application/x-www-form-urlencoded',
},
followRedirects: false,
validateStatus: (status) {
return status != null && status < 400;
},
),
);

if (result['status_code'] == 200) {
if (response.statusCode == 200) {
await presentationActivity(
credentialModels: credentialsToBePresented,
issuer: issuer,
Expand All @@ -529,14 +537,41 @@ class ScanCubit extends Cubit<ScanState> {
),
),
);
} else if (response.statusCode == 302) {
await presentationActivity(
credentialModels: credentialsToBePresented,
issuer: issuer,
);

String? url;

if (response.headers.map.containsKey('location') &&
response.headers.map['location'] != null &&
response.headers.map['location'] is List<dynamic> &&
(response.headers.map['location']!).isNotEmpty) {
url = response.headers.map['location']![0];
}

if (url != null) {
final uri = Uri.parse(url);
if (uri.toString().startsWith(Parameters.oidc4vcUniversalLink)) {
emit(state.copyWith(status: ScanStatus.goBack));
await qrCodeScanCubit.authorizedFlowCompletion(uri);
return;
}
} else {
throw ResponseMessage(
message: ResponseString.RESPONSE_STRING_thisRequestIsNotSupported,
);
}
} else {
throw ResponseMessage(
message: ResponseString
.RESPONSE_STRING_SOMETHING_WENT_WRONG_TRY_AGAIN_LATER,
);
}
} catch (e, s) {
log.e('something went wrong', error: e, stackTrace: s);
log.e('something went wrong - $e', error: e, stackTrace: s);
emitError(e);
}
}
Expand Down Expand Up @@ -587,6 +622,7 @@ class ScanCubit extends Cubit<ScanState> {
'format': 'jwt_vp',
'path': r'$',
'path_nested': {
'id': descriptor.id,
'format': format,
'path': r'$.verifiableCredential',
},
Expand All @@ -598,10 +634,12 @@ class ScanCubit extends Cubit<ScanState> {
for (final InputDescriptor inputDescriptor
in presentationDefinition.inputDescriptors) {
for (final Field field in inputDescriptor.constraints!.fields!) {
final credentialName =
field.filter!.pattern ?? field.filter!.contains!.containsConst;
if (credentialsToBePresented[i]
.credentialPreview
.type
.contains(field.filter!.pattern)) {
.contains(credentialName)) {
descriptor = inputDescriptor;
}
}
Expand All @@ -612,6 +650,7 @@ class ScanCubit extends Cubit<ScanState> {
'format': 'jwt_vp',
'path': r'$',
'path_nested': {
'id': descriptor.id,
'format': format,
// ignore: prefer_interpolation_to_compose_strings
'path': r'$.verifiableCredential[' + i.toString() + ']',
Expand Down
4 changes: 4 additions & 0 deletions lib/splash/bloclisteners/blocklisteners.dart
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,10 @@ final scanBlocListener = BlocListener<ScanCubit, ScanState>(
if (state.status == ScanStatus.error) {
Navigator.of(context).pop();
}

if (state.status == ScanStatus.goBack) {
Navigator.of(context).pop();
}
},
);

Expand Down

0 comments on commit df6ca9d

Please sign in to comment.