Skip to content

Commit

Permalink
feat: Draft 13, authorization code flow fails with scope #2388
Browse files Browse the repository at this point in the history
  • Loading branch information
bibash28 committed Feb 15, 2024
1 parent 3e79fbe commit 5da4e0a
Showing 1 changed file with 65 additions and 25 deletions.
90 changes: 65 additions & 25 deletions packages/oidc4vc/lib/src/oidc4vc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -203,38 +203,78 @@ class OIDC4VC {
for (final credential in selectedCredentials) {
late Map<String, dynamic> data;
if (credential is String) {
//
final credentialsSupported = openIdConfiguration.credentialsSupported;
if (openIdConfiguration.credentialsSupported != null) {
final credentialsSupported = openIdConfiguration.credentialsSupported;

dynamic credentailData;

for (final dynamic cred in credentialsSupported!) {
if (cred is Map<String, dynamic> &&
((cred.containsKey('scope') &&
cred['scope'].toString() == credential) ||
(cred.containsKey('id') &&
cred['id'].toString() == credential))) {
credentailData = cred;
break;
}
}

if (credentialsSupported == null) {
throw Exception();
}
if (credentailData == null) {
throw Exception('CREDENTIAL_SUPPORT_DATA_ERROR');
}

data = {
'type': 'openid_credential',
'locations': [issuer],
'format': credentailData['format'],
'types': credentailData['types'],
};

credentials.add((credentailData['types'] as List<dynamic>).last);
} else if (openIdConfiguration.credentialConfigurationsSupported !=
null) {
// draft 13 case
final credentialsSupported =
openIdConfiguration.credentialConfigurationsSupported;

if (credentialsSupported is! Map<String, dynamic>) {
throw Exception('CREDENTIAL_SUPPORT_DATA_ERROR');
}

final credentialSupportedMapEntry =
credentialsSupported.entries.where(
(entry) {
final dynamic ele = entry.key;

if (ele == credential) return true;

dynamic credentailData;
return false;
},
).firstOrNull;

for (final dynamic cred in credentialsSupported) {
if (cred is Map<String, dynamic> &&
((cred.containsKey('scope') &&
cred['scope'].toString() == credential) ||
(cred.containsKey('id') &&
cred['id'].toString() == credential))) {
credentailData = cred;
break;
if (credentialSupportedMapEntry == null) {
throw Exception('CREDENTIAL_SUPPORT_DATA_ERROR');
}
}

if (credentailData == null) {
throw Exception();
}
final credentialSupported = credentialSupportedMapEntry.value;

data = {
'type': 'openid_credential',
'locations': [issuer],
'format': credentailData['format'],
'types': credentailData['types'],
};
data = {
'type': 'openid_credential',
'locations': [issuer],
'format': credentialSupported['format'],
//'types': credential['types'],
};

credentials.add((credentailData['types'] as List<dynamic>).last);
final scope = credentialSupported['scope'];

if (scope == null) {
throw Exception('CREDENTIAL_SUPPORT_DATA_ERROR');
}

credentials.add(scope);
} else {
throw Exception('CREDENTIAL_SUPPORT_DATA_ERROR');
}
} else if (credential is Map<String, dynamic>) {
data = {
'type': 'openid_credential',
Expand Down

0 comments on commit 5da4e0a

Please sign in to comment.