Skip to content

Commit

Permalink
feat: Show response data for siopv2 flow and oidc4vp flow #3054
Browse files Browse the repository at this point in the history
  • Loading branch information
bibash28 committed Nov 7, 2024
1 parent bfaad87 commit 0655ccf
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 30 deletions.
25 changes: 23 additions & 2 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 @@ -1223,7 +1223,8 @@ class QRCodeScanCubit extends Cubit<QRCodeScanState> {
final customOidc4vcProfile = profileCubit.state.model.profileSetting
.selfSovereignIdentityOptions.customOidc4vcProfile;

final Response<dynamic> response = await oidc4vc.siopv2Flow(
final Map<String, dynamic> responseData =
await oidc4vc.getDataForSiopV2Flow(
clientId: clientId,
privateKey: privateKey,
did: did,
Expand All @@ -1232,8 +1233,28 @@ class QRCodeScanCubit extends Cubit<QRCodeScanState> {
nonce: nonce,
stateValue: stateValue,
clientType: customOidc4vcProfile.clientType,
proofHeaderType: customOidc4vcProfile.proofHeader,
proofHeader: customOidc4vcProfile.proofHeader,
);

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

final Response<dynamic> response = await oidc4vc.siopv2Flow(
redirectUri: redirectUri ?? responseUri!,
dio: client.dio,
responseData: responseData,
);

String? url;
Expand Down
15 changes: 15 additions & 0 deletions lib/scan/cubit/scan_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,21 @@ class ScanCubit extends Cubit<ScanState> {
body = responseData;
}

if (profileCubit.state.model.isDeveloperMode) {
final value = await qrCodeScanCubit.showDataBeforeSending(
title: 'Response Data',
data: body,
);
if (value) {
qrCodeScanCubit.completer = null;
} else {
qrCodeScanCubit.completer = null;
qrCodeScanCubit.resetNonceAndAccessTokenAndAuthorizationDetails();
qrCodeScanCubit.goBack();
return;
}
}

await Future<void>.delayed(const Duration(seconds: 2));
final response = await client.dio.post<dynamic>(
responseOrRedirectUri,
Expand Down
63 changes: 35 additions & 28 deletions packages/oidc4vc/lib/src/oidc4vc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1398,7 +1398,7 @@ class OIDC4VC {
}
}

Future<Response<dynamic>> siopv2Flow({
Future<Map<String, dynamic>> getDataForSiopV2Flow({
required String clientId,
required String did,
required String kid,
Expand All @@ -1407,40 +1407,47 @@ class OIDC4VC {
required String privateKey,
required String? stateValue,
required ClientType clientType,
required ProofHeaderType proofHeaderType,
required Dio dio,
required ProofHeaderType proofHeader,
}) async {
try {
final private = jsonDecode(privateKey) as Map<String, dynamic>;
final private = jsonDecode(privateKey) as Map<String, dynamic>;

final tokenParameters = VerifierTokenParameters(
privateKey: private,
did: did,
kid: kid,
audience: clientId,
credentials: [],
nonce: nonce,
mediaType: MediaType.basic,
clientType: clientType,
proofHeaderType: proofHeader,
clientId: clientId,
);

final tokenParameters = VerifierTokenParameters(
privateKey: private,
did: did,
kid: kid,
audience: clientId,
credentials: [],
nonce: nonce,
mediaType: MediaType.basic,
clientType: clientType,
proofHeaderType: proofHeaderType,
clientId: clientId,
);
// structures
final verifierIdToken = await getIdToken(tokenParameters);

// structures
final verifierIdToken = await getIdToken(tokenParameters);
final responseData = <String, dynamic>{
'id_token': verifierIdToken,
};

final responseHeaders = {
'Content-Type': 'application/x-www-form-urlencoded',
};
if (stateValue != null) {
responseData['state'] = stateValue;
}

final responseData = <String, dynamic>{
'id_token': verifierIdToken,
};
return responseData;
}

if (stateValue != null) {
responseData['state'] = stateValue;
}
Future<Response<dynamic>> siopv2Flow({
required String redirectUri,
required Dio dio,
required Map<String, dynamic> responseData,
}) async {
final responseHeaders = {
'Content-Type': 'application/x-www-form-urlencoded',
};

try {
final response = await dio.post<dynamic>(
redirectUri,
options: Options(
Expand Down

0 comments on commit 0655ccf

Please sign in to comment.