Skip to content

Commit

Permalink
feat: Added state in the data #1872
Browse files Browse the repository at this point in the history
  • Loading branch information
bibash28 committed Sep 11, 2023
1 parent 08d3782 commit 01d2dc3
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ class QRCodeScanCubit extends Cubit<QRCodeScanState> {
final nonce = response['nonce'];
final clientId = response['client_id'];
final claims = response['claims'];
final stateValue = response['state'];
final presentationDefinition = response['presentation_definition'];
final presentationDefinitionUri =
response['presentation_definition_uri'];
Expand All @@ -297,6 +298,9 @@ class QRCodeScanCubit extends Cubit<QRCodeScanState> {
if (nonce != null) {
queryJson['nonce'] = nonce;
}
if (stateValue != null) {
queryJson['state'] = stateValue;
}
if (clientId != null) {
queryJson['client_id'] = clientId;
}
Expand Down Expand Up @@ -846,6 +850,7 @@ class QRCodeScanCubit extends Cubit<QRCodeScanState> {
final redirectUri = state.uri?.queryParameters['redirect_uri'] ?? '';
final nonce = state.uri?.queryParameters['nonce'] ?? '';
final clientId = state.uri?.queryParameters['client_id'] ?? '';
final stateValue = state.uri?.queryParameters['state'];

final keys = <String>[];
state.uri?.queryParameters.forEach((key, value) => keys.add(key));
Expand Down Expand Up @@ -879,6 +884,7 @@ class QRCodeScanCubit extends Cubit<QRCodeScanState> {
nonce: nonce,
isEBSIV2: currentOIIDC4VCType == OIDC4VCType.EBSIV2,
indexValue: currentOIIDC4VCType.indexValue,
stateValue: stateValue,
);
emit(
state.copyWith(
Expand Down
27 changes: 23 additions & 4 deletions lib/scan/cubit/scan_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ class ScanCubit extends Cubit<ScanState> {
);

final responseType = uri.queryParameters['response_type'] ?? '';
final stateValue = uri.queryParameters['state'];

if (uri.toString().startsWith('openid://') ||
uri.toString().startsWith('openid-vc://?') ||
Expand All @@ -101,6 +102,7 @@ class ScanCubit extends Cubit<ScanState> {
kid: kid,
privateKey: privateKey,
indexValue: currentOIIDC4VCType.indexValue,
stateValue: stateValue,
);
return;
} else if (responseType == 'id_token vp_token') {
Expand Down Expand Up @@ -152,6 +154,7 @@ class ScanCubit extends Cubit<ScanState> {
kid: kid,
privateKey: privateKey,
indexValue: currentOIIDC4VCType.indexValue,
stateValue: stateValue,
);
}

Expand Down Expand Up @@ -534,6 +537,7 @@ class ScanCubit extends Cubit<ScanState> {
final nonce = uri.queryParameters['nonce'] ?? '';
final redirectUri = uri.queryParameters['redirect_uri'] ?? '';
final clientId = uri.queryParameters['client_id'] ?? '';
final stateValue = uri.queryParameters['state'];

final credentialList =
credentialsToBePresented!.map((e) => jsonEncode(e.toJson())).toList();
Expand All @@ -549,6 +553,7 @@ class ScanCubit extends Cubit<ScanState> {
nonce: nonce,
isEBSIV2: isEBSIV2,
indexValue: indexValue,
stateValue: stateValue,
);

await presentationActivity(
Expand Down Expand Up @@ -598,6 +603,7 @@ class ScanCubit extends Cubit<ScanState> {
required String kid,
required Uri uri,
required int indexValue,
required String? stateValue,
}) async {
final log = getLogger('ScanCubit - presentCredentialToOID4VPRequest');
emit(state.loading());
Expand All @@ -622,10 +628,16 @@ class ScanCubit extends Cubit<ScanState> {
presentationDefinition: presentationDefinition,
);

final formData = FormData.fromMap(<String, dynamic>{
final responseData = <String, dynamic>{
'vp_token': vpToken,
'presentation_submission': presentationSubmissionString,
});
};

if (stateValue != null) {
responseData['state'] = stateValue;
}

final formData = FormData.fromMap(responseData);

final result = await client.post(
redirectUri,
Expand Down Expand Up @@ -687,6 +699,7 @@ class ScanCubit extends Cubit<ScanState> {
required String kid,
required Uri uri,
required int indexValue,
required String? stateValue,
}) async {
final log =
getLogger('ScanCubit - presentCredentialToOIDC4VPAndSIOPV2Request');
Expand Down Expand Up @@ -723,11 +736,17 @@ class ScanCubit extends Cubit<ScanState> {
presentationDefinition: presentationDefinition,
);

final formData = FormData.fromMap(<String, dynamic>{
final responseData = <String, dynamic>{
'id_token': idToken,
'vp_token': vpToken,
'presentation_submission': presentationSubmissionString,
});
};

if (stateValue != null) {
responseData['state'] = stateValue;
}

final formData = FormData.fromMap(responseData);

final result = await client.post(
redirectUri,
Expand Down
10 changes: 10 additions & 0 deletions packages/oidc4vc/lib/src/oidc4vc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -735,6 +735,7 @@ class OIDC4VC {
required String nonce,
required bool isEBSIV2,
required int indexValue,
required String? stateValue,
String? mnemonic,
String? privateKey,
}) async {
Expand Down Expand Up @@ -773,6 +774,10 @@ class OIDC4VC {
'vp_token': vpToken,
};

if (stateValue != null) {
responseData['state'] = stateValue;
}

await client.post<dynamic>(
redirectUrl,
options: Options(headers: responseHeaders),
Expand Down Expand Up @@ -863,6 +868,7 @@ class OIDC4VC {
required String nonce,
required bool isEBSIV2,
required int indexValue,
required String? stateValue,
String? mnemonic,
String? privateKey,
}) async {
Expand Down Expand Up @@ -896,6 +902,10 @@ class OIDC4VC {
'id_token': verifierIdToken,
};

if (stateValue != null) {
responseData['state'] = stateValue;
}

await client.post<dynamic>(
redirectUri,
options: Options(headers: responseHeaders),
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: altme
description: AltMe Flutter App
version: 1.20.17+264
version: 1.20.18+267
publish_to: none

environment:
Expand Down

0 comments on commit 01d2dc3

Please sign in to comment.