Skip to content

Commit

Permalink
feat: Update enterprise flow update #2454 #2468
Browse files Browse the repository at this point in the history
  • Loading branch information
bibash28 committed Mar 4, 2024
1 parent 278a264 commit 152dd36
Showing 1 changed file with 37 additions and 17 deletions.
54 changes: 37 additions & 17 deletions lib/enterprise/cubit/enterprise_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,23 @@ class EnterpriseCubit extends Cubit<EnterpriseState> {
SecureStorageKeys.enterpriseEmail,
);

// if (savedEmail != null) {
// if (email == savedEmail) {
// /// if email is matched then update the configuration
// await updateTheConfiguration();
// return;
// } else {
// throw ResponseMessage(
// message:
// ResponseString.RESPONSE_STRING_thisWalleIsAlreadyConfigured,
// );
// }
// }

if (savedEmail != null) {
if (email == savedEmail) {
/// if email is matched then update the configuration
await updateTheConfiguration();
return;
} else {
throw ResponseMessage(
message:
ResponseString.RESPONSE_STRING_thisWalleIsAlreadyConfigured,
);
}
throw ResponseMessage(
message: ResponseString.RESPONSE_STRING_thisWalleIsAlreadyConfigured,
);
}

/// get vc and store it in the wallet
Expand Down Expand Up @@ -273,7 +279,7 @@ class EnterpriseCubit extends Cubit<EnterpriseState> {
data: data,
);

String jwtVc = response.toString();
final jwtVc = response.toString();

/// parse
final header = jwtDecode.parseJwtHeader(jwtVc!);
Expand All @@ -299,26 +305,40 @@ class EnterpriseCubit extends Cubit<EnterpriseState> {
try {
emit(state.loading());

final savedEmail = await profileCubit.secureStorageProvider.get(
SecureStorageKeys.enterpriseEmail,
);
final savedPassword = await profileCubit.secureStorageProvider.get(
SecureStorageKeys.enterprisePassword,
);

final provider = await profileCubit.secureStorageProvider.get(
SecureStorageKeys.enterpriseWalletProvider,
);

if (provider == null) {
final walletAttestationData =
await profileCubit.secureStorageProvider.get(
SecureStorageKeys.walletAttestationData,
);

if (savedEmail == null ||
savedPassword == null ||
provider == null ||
walletAttestationData == null) {
throw ResponseMessage(
data: {
'error': 'invalid_request',
'error_description': 'The wallet provider does not match.',
'error_description': 'The wallet is not configured yet.',
},
);
}

final walletAttestationData =
await profileCubit.secureStorageProvider.get(
SecureStorageKeys.walletAttestationData,
);
final encodedData = utf8.encode('$savedEmail:$savedPassword');
final base64Encoded = base64UrlEncode(encodedData).replaceAll('=', '');

final headers = <String, dynamic>{
'Content-Type': 'application/x-www-form-urlencoded',
'Authorization': 'Basic $base64Encoded',
};

final data = <String, dynamic>{
Expand Down

0 comments on commit 152dd36

Please sign in to comment.