Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/test_integration' into add-light…
Browse files Browse the repository at this point in the history
…-theme-#2722
  • Loading branch information
hawkbee1 committed Jun 20, 2024
2 parents fa227c4 + beae895 commit 5fa7507
Show file tree
Hide file tree
Showing 15 changed files with 897 additions and 83 deletions.
88 changes: 52 additions & 36 deletions lib/connection_bridge/beacon/cubit/beacon_cubit.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'dart:async';
import 'dart:convert';

import 'package:altme/app/app.dart';
Expand Down Expand Up @@ -31,57 +32,72 @@ class BeaconCubit extends Cubit<BeaconState> {
}
}

Timer? debounce;

void listenToBeacon() {
try {
log.i('listening to beacon');

beacon.getBeaconResponse().listen(
(data) {
(data) async {
final Map<String, dynamic> requestJson =
jsonDecode(data) as Map<String, dynamic>;
final BeaconRequest beaconRequest =
BeaconRequest.fromJson(requestJson);

log.i('beacon response - $requestJson');
log.i('beaconRequest.type - ${beaconRequest.type}');
switch (beaconRequest.type) {
case RequestType.permission:
emit(
state.copyWith(
status: BeaconStatus.permission,
beaconRequest: beaconRequest,
),
);

case RequestType.signPayload:
emit(
state.copyWith(
status: BeaconStatus.signPayload,
beaconRequest: beaconRequest,
),
);

case RequestType.operation:
emit(
state.copyWith(
status: BeaconStatus.operation,
beaconRequest: beaconRequest,
),
);

case RequestType.broadcast:
emit(
state.copyWith(
status: BeaconStatus.broadcast,
beaconRequest: beaconRequest,
),
);

// ignore: no_default_cases
default:

/// cancel previous timer if exists
if (debounce?.isActive ?? false) {
log.w('cancelled bombarded request');
debounce?.cancel();
}

debounce = Timer(const Duration(seconds: 1), () {
switch (beaconRequest.type) {
case RequestType.permission:
emit(
state.copyWith(
status: BeaconStatus.permission,
beaconRequest: beaconRequest,
),
);

case RequestType.signPayload:
emit(
state.copyWith(
status: BeaconStatus.signPayload,
beaconRequest: beaconRequest,
),
);

case RequestType.operation:
emit(
state.copyWith(
status: BeaconStatus.operation,
beaconRequest: beaconRequest,
),
);

case RequestType.broadcast:
emit(
state.copyWith(
status: BeaconStatus.broadcast,
beaconRequest: beaconRequest,
),
);

// ignore: no_default_cases
default:
break;
}
debounce?.cancel();
});
},
);
} catch (e) {
debounce?.cancel();
log.e('beacon listening error - $e');
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,11 +244,7 @@ class CredentialModel extends Equatable {
credentialPreview.credentialSubjectModel.credentialSubjectType ==
CredentialSubjectType.walletCredential;

String get getFormat => format != null
? format!
: jwt != null
? 'jwt_vc_json-ld'
: 'ldp_vc';
String get getFormat => format != null ? format! : 'ldp_vc';

@override
List<Object?> get props => [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,22 @@ List<CredentialModel> filterCredenialListByFormat({
(CredentialModel credentialModel) {
/// remove ldpVc
if (presentLdpVc) {
return credentialModel.format != VCFormatType.ldpVc.vcValue;
return credentialModel.getFormat != VCFormatType.ldpVc.vcValue;
}

/// remove jwtVc
if (presentJwtVc) {
return credentialModel.format != VCFormatType.jwtVc.vcValue;
return credentialModel.getFormat != VCFormatType.jwtVc.vcValue;
}

/// remove JwtVcJson
if (presentJwtVcJson) {
return credentialModel.format != VCFormatType.jwtVcJson.vcValue;
return credentialModel.getFormat != VCFormatType.jwtVcJson.vcValue;
}

/// remove vcSdJwt
if (presentVcSdJwt) {
return credentialModel.format != VCFormatType.vcSdJWT.vcValue;
return credentialModel.getFormat != VCFormatType.vcSdJWT.vcValue;
}

return false;
Expand Down
10 changes: 6 additions & 4 deletions lib/oidc4vc/get_authorization_uri_for_issuer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -98,21 +98,23 @@ Future<void> getAuthorizationUriForIssuer({
vcFormatType: vcFormatType,
clientAssertion: clientAssertion,
secureAuthorizedFlow: secureAuthorizedFlow,
credentialOfferJson: credentialOfferJson,
dio: client.dio,
);

final requirePushedAuthorizationRequests =
openIdConfiguration.requirePushedAuthorizationRequests;

if ((requirePushedAuthorizationRequests != null &&
requirePushedAuthorizationRequests) ||
(requirePushedAuthorizationRequests == null && secureAuthorizedFlow)) {
if (requirePushedAuthorizationRequests || secureAuthorizedFlow) {
final headers = <String, dynamic>{
'Content-Type': 'application/x-www-form-urlencoded',
};
final parUrl = openIdConfiguration.pushedAuthorizationRequestEndpoint ??
'$authorizationEndpoint/par';

/// error we shuld get it from
final response = await client.post(
'$authorizationEndpoint/par',
parUrl,
headers: headers,
data: authorizationRequestParemeters,
);
Expand Down
2 changes: 1 addition & 1 deletion packages/credential_manifest/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ dependencies:
flutter:
sdk: flutter
json_annotation: ^4.8.1
json_path: ^0.4.4 #latest version creates test issue
json_path: ^0.7.2 #latest version creates test issue

dev_dependencies:
build_runner: ^2.4.4
Expand Down
7 changes: 7 additions & 0 deletions packages/oidc4vc/lib/src/models/openid_configuration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ class OpenIdConfiguration extends Equatable {
const OpenIdConfiguration({
required this.requirePushedAuthorizationRequests,
this.authorizationServer,
this.authorizationServers,
this.credentialsSupported,
this.credentialConfigurationsSupported,
this.credentialEndpoint,
this.pushedAuthorizationRequestEndpoint,
this.credentialIssuer,
this.subjectSyntaxTypesSupported,
this.tokenEndpoint,
Expand All @@ -32,6 +34,8 @@ class OpenIdConfiguration extends Equatable {

@JsonKey(name: 'authorization_server')
final String? authorizationServer;
@JsonKey(name: 'authorization_servers')
final List<String>? authorizationServers;
@JsonKey(name: 'credential_endpoint')
final String? credentialEndpoint;
@JsonKey(name: 'credential_issuer')
Expand All @@ -44,6 +48,8 @@ class OpenIdConfiguration extends Equatable {
final String? batchEndpoint;
@JsonKey(name: 'authorization_endpoint')
final String? authorizationEndpoint;
@JsonKey(name: 'pushed_authorization_request_endpoint')
final String? pushedAuthorizationRequestEndpoint;
@JsonKey(name: 'subject_trust_frameworks_supported')
final List<dynamic>? subjectTrustFrameworksSupported;
@JsonKey(name: 'credentials_supported')
Expand Down Expand Up @@ -71,6 +77,7 @@ class OpenIdConfiguration extends Equatable {
@override
List<Object?> get props => [
authorizationServer,
authorizationServers,
credentialEndpoint,
credentialIssuer,
subjectSyntaxTypesSupported,
Expand Down
88 changes: 68 additions & 20 deletions packages/oidc4vc/lib/src/oidc4vc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ class OIDC4VC {
required String? clientAssertion,
required bool secureAuthorizedFlow,
required Dio dio,
required dynamic credentialOfferJson,
SecureStorageProvider? secureStorage,
}) async {
try {
Expand All @@ -159,11 +160,12 @@ class OIDC4VC {
secureStorage: secureStorage,
);

final authorizationEndpoint = await readAuthorizationEndPoint(
final credentialAuthorizationEndpoint = await readAuthorizationEndPoint(
openIdConfiguration: openIdConfiguration,
issuer: issuer,
oidc4vciDraftType: oidc4vciDraftType,
dio: dio,
credentialOfferJson: credentialOfferJson,
secureStorage: secureStorage,
);

Expand All @@ -188,7 +190,7 @@ class OIDC4VC {
);

return (
authorizationEndpoint,
credentialAuthorizationEndpoint,
authorizationRequestParemeters,
openIdConfiguration,
);
Expand Down Expand Up @@ -861,29 +863,75 @@ class OIDC4VC {
required String issuer,
required OIDC4VCIDraftType oidc4vciDraftType,
required Dio dio,
required dynamic credentialOfferJson,
SecureStorageProvider? secureStorage,
}) async {
var authorizationEndpoint = '$issuer/authorize';
String? authorizationEndpoint;

if (openIdConfiguration.authorizationEndpoint != null) {
authorizationEndpoint = openIdConfiguration.authorizationEndpoint!;
} else {
final authorizationServer =
openIdConfiguration.authorizationServer ?? issuer;
switch (oidc4vciDraftType) {
case OIDC4VCIDraftType.draft11:
if (openIdConfiguration.authorizationEndpoint != null) {
authorizationEndpoint = openIdConfiguration.authorizationEndpoint;
} else {
final authorizationServer =
openIdConfiguration.authorizationServer ?? issuer;

final authorizationServerConfiguration = await getOpenIdConfig(
baseUrl: authorizationServer,
isAuthorizationServer: true,
dio: dio,
secureStorage: secureStorage,
);
final authorizationServerConfiguration = await getOpenIdConfig(
baseUrl: authorizationServer,
isAuthorizationServer: true,
dio: dio,
secureStorage: secureStorage,
);

if (authorizationServerConfiguration.authorizationEndpoint != null) {
authorizationEndpoint =
authorizationServerConfiguration.authorizationEndpoint!;
}
if (authorizationServerConfiguration.authorizationEndpoint != null) {
authorizationEndpoint =
authorizationServerConfiguration.authorizationEndpoint;
}
}
case OIDC4VCIDraftType.draft13:

/// Extract the authorization endpoint from from first element of
/// authorization_servers in opentIdConfiguration.authorizationServers
final listOpenIDConfiguration =
openIdConfiguration.authorizationServers ?? [];
if (listOpenIDConfiguration.isNotEmpty) {
if (listOpenIDConfiguration.length == 1) {
authorizationEndpoint =
'${listOpenIDConfiguration.first}/authorize';
} else {
try {
/// Extract the authorization endpoint from from
/// authorization_server in credentialOfferJson
final jsonPathCredentialOffer = JsonPath(
// ignore: lines_longer_than_80_chars
r'$..["urn:ietf:params:oauth:grant-type:pre-authorized_code"].authorization_server',
);
final data = jsonPathCredentialOffer
.read(credentialOfferJson)
.first
.value! as String;
if (listOpenIDConfiguration.contains(data)) {
authorizationEndpoint = '$data/authorize';
}
} catch (e) {
final jsonPathCredentialOffer = JsonPath(
r'$..authorization_code.authorization_server',
);
final data = jsonPathCredentialOffer
.read(credentialOfferJson)
.first
.value! as String;
if (data.isNotEmpty && listOpenIDConfiguration.contains(data)) {
authorizationEndpoint = '$data/authorize';
}
}
}
}
}
return authorizationEndpoint;
// If authorizationEndpoint is null, we consider the issuer
// as the authorizationEndpoint

return authorizationEndpoint ??= '$issuer/authorize';
}

String readIssuerDid(
Expand Down Expand Up @@ -1655,7 +1703,7 @@ class OIDC4VC {
////openid-issuer-configuration or some are in the /openid-configuration
///(token endpoint etc,) and other are in the /openid-credential-issuer
///(credential supported) for OIDC4VP and SIOPV2, the serve is a client,
///the wallet is the suthorization server the verifier metadata are in
///the wallet is the authorization server the verifier metadata are in
////openid-configuration
final url = '$baseUrl/.well-known/openid-configuration';
Expand Down
2 changes: 1 addition & 1 deletion packages/oidc4vc/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ dependencies:
http_mock_adapter: ^0.6.0
jose_plus: ^0.4.5
json_annotation: ^4.8.1
json_path: ^0.4.4 #latest version creates test issue
json_path: ^0.7.2 #latest version creates test issue
secp256k1: ^0.3.0
secure_storage:
path: ../secure_storage
Expand Down
1 change: 1 addition & 0 deletions packages/oidc4vc/test/configuration/configuration.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export 'issuance/issuance.dart';
1 change: 1 addition & 0 deletions packages/oidc4vc/test/configuration/issuance/issuance.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export 'test10.dart';
Loading

0 comments on commit 5fa7507

Please sign in to comment.