Skip to content

Commit

Permalink
Merge pull request #66 from nevissecurity/feature/NEVISACCESSAPP-6355-…
Browse files Browse the repository at this point in the history
…Introduce-builder-pattern-for-configuration

NEVISACCESSAPP-6355: Introduce builder pattern for Configuration
  • Loading branch information
tamas-toth authored Jan 7, 2025
2 parents b2f60b1 + 92454ba commit 0214db1
Show file tree
Hide file tree
Showing 13 changed files with 188 additions and 82 deletions.
38 changes: 19 additions & 19 deletions android/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ GEM
artifactory (3.0.17)
atomos (0.1.3)
aws-eventstream (1.3.0)
aws-partitions (1.1006.0)
aws-sdk-core (3.212.0)
aws-partitions (1.1031.0)
aws-sdk-core (3.214.1)
aws-eventstream (~> 1, >= 1.3.0)
aws-partitions (~> 1, >= 1.992.0)
aws-sigv4 (~> 1.9)
jmespath (~> 1, >= 1.6.1)
aws-sdk-kms (1.95.0)
aws-sdk-kms (1.96.0)
aws-sdk-core (~> 3, >= 3.210.0)
aws-sigv4 (~> 1.5)
aws-sdk-s3 (1.170.1)
aws-sdk-s3 (1.177.0)
aws-sdk-core (~> 3, >= 3.210.0)
aws-sdk-kms (~> 1)
aws-sigv4 (~> 1.5)
Expand Down Expand Up @@ -58,17 +58,17 @@ GEM
faraday-em_synchrony (1.0.0)
faraday-excon (1.1.0)
faraday-httpclient (1.0.1)
faraday-multipart (1.0.4)
multipart-post (~> 2)
faraday-multipart (1.1.0)
multipart-post (~> 2.0)
faraday-net_http (1.0.2)
faraday-net_http_persistent (1.2.0)
faraday-patron (1.0.0)
faraday-rack (1.0.0)
faraday-retry (1.0.3)
faraday_middleware (1.2.1)
faraday (~> 1.0)
fastimage (2.3.1)
fastlane (2.225.0)
fastimage (2.4.0)
fastlane (2.226.0)
CFPropertyList (>= 2.3, < 4.0.0)
addressable (>= 2.8, < 3.0.0)
artifactory (~> 3.0)
Expand Down Expand Up @@ -108,7 +108,7 @@ GEM
tty-spinner (>= 0.8.0, < 1.0.0)
word_wrap (~> 1.0.0)
xcodeproj (>= 1.13.0, < 2.0.0)
xcpretty (~> 0.3.0)
xcpretty (~> 0.4.0)
xcpretty-travis-formatter (>= 0.0.3, < 2.0.0)
fastlane-plugin-firebase_app_distribution (0.9.1)
google-apis-firebaseappdistribution_v1 (~> 0.3.0)
Expand Down Expand Up @@ -157,12 +157,12 @@ GEM
os (>= 0.9, < 2.0)
signet (>= 0.16, < 2.a)
highline (2.0.3)
http-cookie (1.0.7)
http-cookie (1.0.8)
domain_name (~> 0.5)
httpclient (2.8.3)
jmespath (1.6.2)
json (2.8.2)
jwt (2.9.3)
json (2.9.1)
jwt (2.10.1)
base64
mini_magick (4.13.2)
mini_mime (1.1.5)
Expand All @@ -173,18 +173,18 @@ GEM
nkf (0.2.0)
optparse (0.6.0)
os (1.1.4)
plist (3.7.1)
plist (3.7.2)
public_suffix (6.0.1)
rake (13.2.1)
representable (3.2.0)
declarative (< 0.1.0)
trailblazer-option (>= 0.1.1, < 0.2.0)
uber (< 0.2.0)
retriable (3.1.2)
rexml (3.3.9)
rouge (2.0.7)
rexml (3.4.0)
rouge (3.28.0)
ruby2_keywords (0.0.5)
rubyzip (2.3.2)
rubyzip (2.4.1)
security (0.1.5)
signet (0.19.0)
addressable (~> 2.8)
Expand Down Expand Up @@ -213,8 +213,8 @@ GEM
colored2 (~> 3.1)
nanaimo (~> 0.4.0)
rexml (>= 3.3.6, < 4.0)
xcpretty (0.3.0)
rouge (~> 2.0.7)
xcpretty (0.4.0)
rouge (~> 3.28.0)
xcpretty-travis-formatter (1.0.1)
xcpretty (~> 0.2, >= 0.0.7)

Expand All @@ -228,4 +228,4 @@ DEPENDENCIES
fastlane-plugin-firebase_app_distribution

BUNDLED WITH
2.5.23
2.6.2
6 changes: 1 addition & 5 deletions assets/config_authentication_cloud.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@
},
"sdk": {
"hostname": "myinstance.mauth.nevis.cloud",
"facetId": "android:apk-key-hash:ch.nevis.mobile.authentication.sdk.flutter.example",
"networkTimeoutInSeconds": "60",
"authenticationMaxRetries": 3,
"authenticationRetryIntervalInSeconds": "1",
"userInteractionTimeoutInSeconds": "240"
"facetId": "android:apk-key-hash:ch.nevis.mobile.authentication.sdk.flutter.example"
},
"authenticatorAllowlist": [
"F1D0#0001",
Expand Down
6 changes: 1 addition & 5 deletions assets/config_identity_suite.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,7 @@
"authenticationResponsePath": "/auth/fidouaf/authenticationresponse/",
"deregistrationRequestPath": "/nevisfido/uaf/1.1/request/deregistration/",
"dispatchTargetResourcePath": "/nevisfido/token/dispatch/targets/",
"deviceResourcePath": "/nevisfido/devices/",
"networkTimeoutInSeconds": "60",
"authenticationMaxRetries": 3,
"authenticationRetryIntervalInSeconds": "1",
"userInteractionTimeoutInSeconds": "240"
"deviceResourcePath": "/nevisfido/devices/"
},
"authenticatorAllowlist": [
"F1D0#0001",
Expand Down
54 changes: 27 additions & 27 deletions ios/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ GEM
base64
nkf
rexml
activesupport (7.2.2)
activesupport (7.2.2.1)
base64
benchmark (>= 0.3)
bigdecimal
Expand All @@ -25,16 +25,16 @@ GEM
artifactory (3.0.17)
atomos (0.1.3)
aws-eventstream (1.3.0)
aws-partitions (1.1006.0)
aws-sdk-core (3.212.0)
aws-partitions (1.1031.0)
aws-sdk-core (3.214.1)
aws-eventstream (~> 1, >= 1.3.0)
aws-partitions (~> 1, >= 1.992.0)
aws-sigv4 (~> 1.9)
jmespath (~> 1, >= 1.6.1)
aws-sdk-kms (1.95.0)
aws-sdk-kms (1.96.0)
aws-sdk-core (~> 3, >= 3.210.0)
aws-sigv4 (~> 1.5)
aws-sdk-s3 (1.170.1)
aws-sdk-s3 (1.177.0)
aws-sdk-core (~> 3, >= 3.210.0)
aws-sdk-kms (~> 1)
aws-sigv4 (~> 1.5)
Expand All @@ -43,7 +43,7 @@ GEM
babosa (1.0.4)
base64 (0.2.0)
benchmark (0.4.0)
bigdecimal (3.1.8)
bigdecimal (3.1.9)
claide (1.1.0)
cocoapods (1.16.2)
addressable (~> 2.8)
Expand Down Expand Up @@ -118,17 +118,17 @@ GEM
faraday-em_synchrony (1.0.0)
faraday-excon (1.1.0)
faraday-httpclient (1.0.1)
faraday-multipart (1.0.4)
multipart-post (~> 2)
faraday-multipart (1.1.0)
multipart-post (~> 2.0)
faraday-net_http (1.0.2)
faraday-net_http_persistent (1.2.0)
faraday-patron (1.0.0)
faraday-rack (1.0.0)
faraday-retry (1.0.3)
faraday_middleware (1.2.1)
faraday (~> 1.0)
fastimage (2.3.1)
fastlane (2.225.0)
fastimage (2.4.0)
fastlane (2.226.0)
CFPropertyList (>= 2.3, < 4.0.0)
addressable (>= 2.8, < 3.0.0)
artifactory (~> 3.0)
Expand Down Expand Up @@ -168,16 +168,16 @@ GEM
tty-spinner (>= 0.8.0, < 1.0.0)
word_wrap (~> 1.0.0)
xcodeproj (>= 1.13.0, < 2.0.0)
xcpretty (~> 0.3.0)
xcpretty (~> 0.4.0)
xcpretty-travis-formatter (>= 0.0.3, < 2.0.0)
fastlane-plugin-firebase_app_distribution (0.9.1)
google-apis-firebaseappdistribution_v1 (~> 0.3.0)
google-apis-firebaseappdistribution_v1alpha (~> 0.2.0)
fastlane-sirp (1.0.0)
sysrandom (~> 1.0)
ffi (1.17.0)
ffi (1.17.0-arm64-darwin)
ffi (1.17.0-x86_64-darwin)
ffi (1.17.1)
ffi (1.17.1-arm64-darwin)
ffi (1.17.1-x86_64-darwin)
fourflusher (2.3.1)
fuzzy_match (2.0.4)
gh_inspector (1.1.3)
Expand Down Expand Up @@ -222,19 +222,19 @@ GEM
os (>= 0.9, < 2.0)
signet (>= 0.16, < 2.a)
highline (2.0.3)
http-cookie (1.0.7)
http-cookie (1.0.8)
domain_name (~> 0.5)
httpclient (2.8.3)
i18n (1.14.6)
concurrent-ruby (~> 1.0)
jmespath (1.6.2)
json (2.8.2)
jwt (2.9.3)
json (2.9.1)
jwt (2.10.1)
base64
logger (1.6.1)
logger (1.6.4)
mini_magick (4.13.2)
mini_mime (1.1.5)
minitest (5.25.1)
minitest (5.25.4)
molinillo (0.8.0)
multi_json (1.15.0)
multipart-post (2.4.1)
Expand All @@ -245,20 +245,20 @@ GEM
nkf (0.2.0)
optparse (0.6.0)
os (1.1.4)
plist (3.7.1)
plist (3.7.2)
public_suffix (4.0.7)
rake (13.2.1)
representable (3.2.0)
declarative (< 0.1.0)
trailblazer-option (>= 0.1.1, < 0.2.0)
uber (< 0.2.0)
retriable (3.1.2)
rexml (3.3.9)
rouge (2.0.7)
rexml (3.4.0)
rouge (3.28.0)
ruby-macho (2.5.1)
ruby2_keywords (0.0.5)
rubyzip (2.3.2)
securerandom (0.3.2)
rubyzip (2.4.1)
securerandom (0.4.1)
security (0.1.5)
signet (0.19.0)
addressable (~> 2.8)
Expand Down Expand Up @@ -291,8 +291,8 @@ GEM
colored2 (~> 3.1)
nanaimo (~> 0.4.0)
rexml (>= 3.3.6, < 4.0)
xcpretty (0.3.0)
rouge (~> 2.0.7)
xcpretty (0.4.0)
rouge (~> 3.28.0)
xcpretty-travis-formatter (1.0.1)
xcpretty (~> 0.2, >= 0.0.7)

Expand All @@ -307,4 +307,4 @@ DEPENDENCIES
fastlane-plugin-firebase_app_distribution

BUNDLED WITH
2.5.23
2.6.2
50 changes: 45 additions & 5 deletions lib/configuration/configuration_loader.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'dart:convert';

import 'package:flutter/services.dart';
import 'package:injectable/injectable.dart';
import 'package:nevis_mobile_authentication_sdk/nevis_mobile_authentication_sdk.dart';
import 'package:nevis_mobile_authentication_sdk_example_app_flutter/configuration/model/app_configuration.dart';
import 'package:nevis_mobile_authentication_sdk_example_app_flutter/configuration/model/app_environment.dart';

Expand All @@ -13,16 +14,55 @@ const identitySuite = Environment('identitySuite');

abstract class ConfigurationLoader {
AppEnvironment get environment;
AppConfiguration? configuration;

Future<AppConfiguration> load() async {
if (configuration != null) return Future.value(configuration);
AppConfiguration? _appConfiguration;
Configuration? _sdkConfiguration;

Future<AppConfiguration> appConfiguration() async {
if (_appConfiguration != null) {
return Future.value(_appConfiguration);
}

final configFile = environment.configFileName;
final jsonString = await rootBundle.loadString('assets/$configFile');
final dynamic jsonMap = jsonDecode(jsonString);
configuration = AppConfiguration.fromJson(jsonMap);
return Future.value(configuration);
_appConfiguration = AppConfiguration.fromJson(jsonMap);
return Future.value(_appConfiguration);
}

Future<Configuration> sdkConfiguration() async {
if (_sdkConfiguration != null) {
return Future.value(_sdkConfiguration);
}

final appConfiguration = await this.appConfiguration();
switch (environment) {
case AppEnvironment.authenticationCloud:
_sdkConfiguration = Configuration.authCloudBuilder()
.hostname(appConfiguration.sdk.hostname!)
.facetId(appConfiguration.sdk.facetId!)
.build();
case AppEnvironment.identitySuite:
_sdkConfiguration = Configuration.builder()
.baseUrl(appConfiguration.sdk.baseUrl!)
.facetId(appConfiguration.sdk.facetId!)
.registrationRequestPath(
appConfiguration.sdk.registrationRequestPath!)
.registrationResponsePath(
appConfiguration.sdk.registrationResponsePath!)
.authenticationRequestPath(
appConfiguration.sdk.authenticationRequestPath!)
.authenticationResponsePath(
appConfiguration.sdk.authenticationResponsePath!)
.deregistrationRequestPath(
appConfiguration.sdk.deregistrationRequestPath!)
.dispatchTargetResourcePath(
appConfiguration.sdk.dispatchTargetResourcePath!)
.deviceResourcePath(appConfiguration.sdk.deviceResourcePath!)
.build();
}

return Future.value(_sdkConfiguration!);
}
}

Expand Down
6 changes: 3 additions & 3 deletions lib/configuration/model/app_configuration.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Copyright © 2022 Nevis Security AG. All rights reserved.

import 'package:json_annotation/json_annotation.dart';
import 'package:nevis_mobile_authentication_sdk/nevis_mobile_authentication_sdk.dart';
import 'package:nevis_mobile_authentication_sdk_example_app_flutter/configuration/model/login_configuration.dart';
import 'package:nevis_mobile_authentication_sdk_example_app_flutter/configuration/model/sdk_configuration.dart';

part 'app_configuration.g.dart';

Expand Down Expand Up @@ -32,13 +32,13 @@ class AppConfiguration {
LoginConfiguration loginConfiguration;

@JsonKey(name: "sdk")
Configuration sdkConfiguration;
SdkConfiguration sdk;

AppConfiguration({
required this.allowClass2Sensors,
required this.authenticatorAllowlist,
required this.loginConfiguration,
required this.sdkConfiguration,
required this.sdk,
});

factory AppConfiguration.fromJson(Map<String, dynamic> json) =>
Expand Down
5 changes: 2 additions & 3 deletions lib/configuration/model/app_configuration.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 0214db1

Please sign in to comment.