Skip to content

Commit

Permalink
OIDC4VCI pick credentials to issue
Browse files Browse the repository at this point in the history
  • Loading branch information
hawkbee1 committed Jan 17, 2025
1 parent 3a05d9b commit 9d443b0
Show file tree
Hide file tree
Showing 13 changed files with 479 additions and 486 deletions.
30 changes: 23 additions & 7 deletions lib/app/shared/helper_functions/helper_functions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,8 @@ Future<Oidc4vcParameters> getIssuanceData({
late Map<String, dynamic> credentialOfferJson;
String? issuer;
String? preAuthorizedCode;
bool userPinRequired = false;
TxCode? txCode;

if (keys.contains('credential_offer') ||
keys.contains('credential_offer_uri')) {
Expand All @@ -716,11 +718,22 @@ Future<Oidc4vcParameters> getIssuanceData({
if (grants != null && grants is Map) {
final dynamic preAuthorizedCodeGrant =
grants['urn:ietf:params:oauth:grant-type:pre-authorized_code'];
if (preAuthorizedCodeGrant != null &&
preAuthorizedCodeGrant is Map &&
preAuthorizedCodeGrant.containsKey('pre-authorized_code')) {
preAuthorizedCode =
preAuthorizedCodeGrant['pre-authorized_code'] as String;
if (preAuthorizedCodeGrant != null && preAuthorizedCodeGrant is Map) {
if (preAuthorizedCodeGrant.containsKey('pre-authorized_code')) {
preAuthorizedCode =
preAuthorizedCodeGrant['pre-authorized_code'] as String;
}
if (preAuthorizedCodeGrant.containsKey('user_pin_required')) {
userPinRequired = preAuthorizedCodeGrant['user_pin_required'] as bool;
} else if (preAuthorizedCodeGrant.containsKey('tx_code')) {
/// draft 13
final txCodeMap = preAuthorizedCodeGrant['tx_code'];

if (txCodeMap is Map<String, dynamic>) {
txCode = TxCode.fromJson(txCodeMap);
userPinRequired = true;
}
}
}

issuer = credentialOfferJson['credential_issuer'].toString();
Expand All @@ -746,6 +759,7 @@ Future<Oidc4vcParameters> getIssuanceData({
return Oidc4vcParameters(
oidc4vciDraftType: oidc4vciDraftType,
useOAuthAuthorizationServerLink: useOAuthAuthorizationServerLink,
initialUri: uri,
);
}

Expand All @@ -771,10 +785,13 @@ Future<Oidc4vcParameters> getIssuanceData({
final Oidc4vcParameters oidc4vcParametersfromIssuer = Oidc4vcParameters(
oidc4vciDraftType: oidc4vciDraftType,
useOAuthAuthorizationServerLink: useOAuthAuthorizationServerLink,
initialUri: uri,
classIssuerOpenIdConfiguration: issuerOpenIdConfiguration,
classCredentialOffer: credentialOfferJson,
preAuthorizedCode: preAuthorizedCode,
classIssuer: issuer,
userPinRequired: userPinRequired,
txCode: txCode,
);
final Oidc4vcParameters oidc4vcParameters =
await oidc4vc.authorizationParameters(
Expand Down Expand Up @@ -832,7 +849,6 @@ Future<Oidc4vcParameters> getIssuanceData({
}

Future<void> handleErrorForOID4VCI({
required String url,
required Oidc4vcParameters oidc4vcParameters,
}) async {
List<dynamic>? subjectSyntaxTypesSupported = oidc4vcParameters
Expand Down Expand Up @@ -1370,7 +1386,7 @@ String getFormattedStringOIDC4VCI({
<b>CREDENTIAL OFFER :</b>
${const JsonEncoder.withIndent(' ').convert(oidc4vcParameters.classCredentialOffer)}\n
<b>AUTHORIZATION SERVER CONFIGURATION :</b>
${oidc4vcParameters.classAuthorizationServerOpenIdConfiguration != null ? const JsonEncoder.withIndent(' ').convert(oidc4vcParameters.classAuthorizationServerOpenIdConfiguration) : 'None'}\n
${oidc4vcParameters.classAuthorizationServerOpenIdConfiguration != const OpenIdConfiguration(requirePushedAuthorizationRequests: false) ? const JsonEncoder.withIndent(' ').convert(oidc4vcParameters.classAuthorizationServerOpenIdConfiguration) : 'None'}\n
<b>CREDENTIAL ISSUER CONFIGURATION :</b>
${const JsonEncoder.withIndent(' ').convert(oidc4vcParameters.classIssuerOpenIdConfiguration)}
''';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,42 +12,26 @@ class Oidc4vcCredentialPickPage extends StatelessWidget {
required this.credentials,
required this.userPin,
required this.txCode,
required this.preAuthorizedCode,
required this.issuer,
required this.isEBSI,
required this.credentialOfferJson,
required this.openIdConfiguration,
required this.oidc4vcParameters,
});

final List<dynamic> credentials;
final String? userPin;
final String? txCode;
final String? preAuthorizedCode;
final String issuer;
final bool isEBSI;
final dynamic credentialOfferJson;
final OpenIdConfiguration openIdConfiguration;
final Oidc4vcParameters oidc4vcParameters;

static Route<dynamic> route({
required List<dynamic> credentials,
required String? userPin,
required String? txCode,
required String? preAuthorizedCode,
required String issuer,
required bool isEBSI,
required dynamic credentialOfferJson,
required OpenIdConfiguration openIdConfiguration,
required Oidc4vcParameters oidc4vcParameters,
}) =>
MaterialPageRoute<void>(
builder: (context) => Oidc4vcCredentialPickPage(
credentials: credentials,
userPin: userPin,
txCode: txCode,
issuer: issuer,
preAuthorizedCode: preAuthorizedCode,
isEBSI: isEBSI,
credentialOfferJson: credentialOfferJson,
openIdConfiguration: openIdConfiguration,
oidc4vcParameters: oidc4vcParameters,
),
settings: const RouteSettings(name: '/Oidc4vcCredentialPickPage'),
);
Expand All @@ -60,11 +44,7 @@ class Oidc4vcCredentialPickPage extends StatelessWidget {
credentials: credentials,
userPin: userPin,
txCode: txCode,
issuer: issuer,
preAuthorizedCode: preAuthorizedCode,
isEBSI: isEBSI,
credentialOfferJson: credentialOfferJson,
openIdConfiguration: openIdConfiguration,
oidc4vcParameters: oidc4vcParameters,
),
);
}
Expand All @@ -76,21 +56,13 @@ class Oidc4vcCredentialPickView extends StatelessWidget {
required this.credentials,
required this.userPin,
required this.txCode,
required this.preAuthorizedCode,
required this.issuer,
required this.isEBSI,
required this.credentialOfferJson,
required this.openIdConfiguration,
required this.oidc4vcParameters,
});

final List<dynamic> credentials;
final String? userPin;
final String? txCode;
final String? preAuthorizedCode;
final String issuer;
final bool isEBSI;
final dynamic credentialOfferJson;
final OpenIdConfiguration openIdConfiguration;
final Oidc4vcParameters oidc4vcParameters;

@override
Widget build(BuildContext context) {
Expand Down Expand Up @@ -140,7 +112,8 @@ class Oidc4vcCredentialPickView extends StatelessWidget {

// fetch for displaying the image
final (Display? display, _) = fetchDisplay(
openIdConfiguration: openIdConfiguration,
openIdConfiguration:
oidc4vcParameters.classIssuerOpenIdConfiguration,
credentialType: credential,
languageCode: languageCode,
);
Expand Down Expand Up @@ -215,12 +188,7 @@ class Oidc4vcCredentialPickView extends StatelessWidget {
selectedCredentials: selectedCredentials,
userPin: userPin,
txCode: txCode,
issuer: issuer,
preAuthorizedCode: preAuthorizedCode,
isEBSI: isEBSI,
credentialOfferJson: credentialOfferJson,
qrCodeScanCubit:
context.read<QRCodeScanCubit>(),
oidc4vcParameters: oidc4vcParameters,
);
},
text: l10n.proceed,
Expand Down
Loading

0 comments on commit 9d443b0

Please sign in to comment.