Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/fp 51 #90

Merged
merged 11 commits into from
May 3, 2023
2 changes: 1 addition & 1 deletion example/ios/.swiftlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ excluded: # paths to ignore during linting. Takes precedence over `included`.
- .swiftlint.yml
- OneginiTests
- OneginiUITests
- .symlinks/plugins/onegini/ios/Classes/Pigeon.swift
- .symlinks/plugins/onegini/ios/Classes/Pigeon.gen.swift

# If true, SwiftLint will not fail if no lintable files are found.
allow_zero_lintable_files: false
Expand Down
2 changes: 1 addition & 1 deletion example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ SPEC CHECKSUMS:
SwiftLint: 1b7561918a19e23bfed960e40759086e70f4dba5
Toast: 91b396c56ee72a5790816f40d3a94dd357abc196
Typhoon: 1973c93ecfb3edb963d78b10e715bc2911475bd2
url_launcher_ios: 839c58cdb4279282219f5e248c3321761ff3c4de
url_launcher_ios: 08a3dfac5fb39e8759aeb0abbd5d9480f30fc8b4

PODFILE CHECKSUM: e49c186fd5db1b7547d2a80e7096f4e0713e90f9

Expand Down
274 changes: 121 additions & 153 deletions example/lib/screens/user_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ class _UserScreenState extends State<UserScreen> with RouteAware {
});
}

Widget biometricAuthenticatorWidget() {
Widget _buildBiometricAuthenticatorWidget() {
final authenticator = _biometricAuthenticator;
if (authenticator != null) {
return ListTile(
Expand All @@ -177,32 +177,38 @@ class _UserScreenState extends State<UserScreen> with RouteAware {
return SizedBox.shrink();
}

Widget preferredAuthenticatorSelectorWidget() {
Widget _buildPreferredAuthenticatorWidget() {
final biometricAuthenticator = _biometricAuthenticator;
return PopupMenuButton<OWAuthenticatorType>(
child: ListTile(
title: Text("set preferred authenticator"),
leading: Icon(Icons.add_to_home_screen),
),
onSelected: (value) {
Onegini.instance.userClient
.setPreferredAuthenticator(value)
.whenComplete(() => getAuthenticators());
},
itemBuilder: (context) {
return [
PopupMenuItem<OWAuthenticatorType>(
child: Text("Pin"),
value: OWAuthenticatorType.pin,
),
if (biometricAuthenticator != null &&
biometricAuthenticator.isRegistered)
return Column(mainAxisSize: MainAxisSize.min, children: [
ListTile(
title:
Text("Preferred Authenticator: ${_preferredAuthenticator?.name} "),
),
PopupMenuButton<OWAuthenticatorType>(
child: ListTile(
title: Text("set preferred authenticator"),
leading: Icon(Icons.add_to_home_screen),
),
onSelected: (value) {
Onegini.instance.userClient
.setPreferredAuthenticator(value)
.whenComplete(() => getAuthenticators());
},
itemBuilder: (context) {
return [
PopupMenuItem<OWAuthenticatorType>(
child: Text(biometricAuthenticator.name),
value: OWAuthenticatorType.biometric,
child: Text("Pin"),
value: OWAuthenticatorType.pin,
),
];
});
if (biometricAuthenticator != null &&
biometricAuthenticator.isRegistered)
PopupMenuItem<OWAuthenticatorType>(
child: Text(biometricAuthenticator.name),
value: OWAuthenticatorType.biometric,
),
];
})
]);
}

@override
Expand Down Expand Up @@ -239,12 +245,8 @@ class _UserScreenState extends State<UserScreen> with RouteAware {
title: Text("Pin"),
leading: Switch(value: true, onChanged: null),
),
biometricAuthenticatorWidget(),
ListTile(
title: Text(
"Preferred Authenticator: ${_preferredAuthenticator?.name} "),
),
preferredAuthenticatorSelectorWidget(),
_buildBiometricAuthenticatorWidget(),
_buildPreferredAuthenticatorWidget(),
Divider(),
ListTile(
title: Text("Change pin"),
Expand Down Expand Up @@ -422,29 +424,102 @@ class Info extends StatefulWidget {
}

class _InfoState extends State<Info> {
Future<ApplicationDetails> getApplicationDetails() async {
Future<ApplicationDetails> _getApplicationDetails() async {
await Onegini.instance.userClient
.authenticateDevice(["read", "write", "application-details"]);
var response = await Onegini.instance.resourcesMethods.requestResource(
final response = await Onegini.instance.resourcesMethods.requestResource(
ResourceRequestType.anonymous,
RequestDetails(
path: "application-details", method: HttpRequestMethod.get));
return applicationDetailsFromJson(response.body);
}

Future<ClientResource> getClientResource() async {
var response = await Onegini.instance.resourcesMethods
Future<ClientResource> _getClientResource() async {
final response = await Onegini.instance.resourcesMethods
.requestResourceAuthenticated(
RequestDetails(path: "devices", method: HttpRequestMethod.get))
// Will be fixed in FP-51
// ignore: body_might_complete_normally_catch_error
.catchError((error) {
print('Caught error: $error');
RequestDetails(path: "devices", method: HttpRequestMethod.get));
return clientResourceFromJson(response.body);
}

showFlutterToast(error.message);
});
FutureBuilder<ClientResource> _buildDeviceInfoList() {
return FutureBuilder<ClientResource>(
future: _getClientResource(),
builder: (context, snapshot) {
final snapshotData = snapshot.data;
return snapshotData != null
? ListView.builder(
itemCount: snapshotData.devices.length,
itemBuilder: (BuildContext context, int index) {
return ExpansionTile(
title: Text(snapshotData.devices[index].name),
expandedCrossAxisAlignment: CrossAxisAlignment.start,
children: [
ListTile(
title: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
"Id => ${snapshotData.devices[index].id}",
style: TextStyle(fontSize: 15),
),
SizedBox(height: 10),
Text(
"Application => ${snapshotData.devices[index].application}",
style: TextStyle(fontSize: 15),
),
SizedBox(height: 10),
Text(
"Mobile authentication enabled => ${snapshotData.devices[index].mobileAuthenticationEnabled.toString()}",
style: TextStyle(fontSize: 15),
),
SizedBox(height: 10),
Text(
"Platform => ${snapshotData.devices[index].platform}",
style: TextStyle(fontSize: 15),
),
SizedBox(),
],
))
],
);
},
)
: Center(
child: SizedBox(
child: CircularProgressIndicator(),
),
);
},
);
}

return clientResourceFromJson(response.body);
FutureBuilder<ApplicationDetails> _buildApplicationDetails() {
return FutureBuilder<ApplicationDetails>(
future: _getApplicationDetails(),
builder: (context, snapshot) {
return snapshot.hasData
? Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
"application identifier => ${snapshot.data?.applicationIdentifier}",
style: TextStyle(fontSize: 15),
),
SizedBox(height: 10),
Text(
"application platform => ${snapshot.data?.applicationPlatform}",
style: TextStyle(fontSize: 15),
),
SizedBox(height: 10),
Text(
"application version => ${snapshot.data?.applicationVersion}",
style: TextStyle(fontSize: 15),
),
],
)
: CircularProgressIndicator();
},
);
}

@override
Expand All @@ -455,118 +530,11 @@ class _InfoState extends State<Info> {
margin: EdgeInsets.all(20),
child: Column(
children: [
SizedBox(
height: 20,
),
FutureBuilder<ApplicationDetails>(
future: getApplicationDetails(),
builder: (context, snapshot) {
return snapshot.hasData
? Column(
children: [
Row(
children: [
Text(
"application identifier => ",
style: TextStyle(fontSize: 15),
),
Text(
snapshot.data?.applicationIdentifier ?? "",
style: TextStyle(fontSize: 15),
)
],
),
SizedBox(
height: 10,
),
Row(
children: [
Text(
"application platform => ",
style: TextStyle(fontSize: 15),
),
Text(
snapshot.data?.applicationPlatform ?? "",
style: TextStyle(fontSize: 15),
)
],
),
SizedBox(
height: 10,
),
Row(
children: [
Text(
"application version => ",
style: TextStyle(fontSize: 15),
),
Text(
snapshot.data?.applicationVersion ?? "",
style: TextStyle(fontSize: 15),
)
],
),
SizedBox(
height: 10,
),
],
)
: Text("");
},
),
SizedBox(height: 20),
_buildApplicationDetails(),
Divider(),
Expanded(
child: FutureBuilder<ClientResource>(
future: getClientResource(),
builder: (context, snapshot) {
final snapshotData = snapshot.data;
return snapshotData != null
? ListView.builder(
itemCount: snapshotData.devices.length,
itemBuilder: (BuildContext context, int index) {
return ExpansionTile(
title: Text(snapshotData.devices[index].name),
expandedCrossAxisAlignment:
CrossAxisAlignment.start,
children: [
Text(
"Id => ${snapshotData.devices[index].id}",
style: TextStyle(fontSize: 18),
),
SizedBox(
height: 10,
),
Text(
"Application => ${snapshotData.devices[index].application}",
style: TextStyle(fontSize: 18),
),
SizedBox(
height: 10,
),
Text(
"Mobile authentication enabled => ${snapshotData.devices[index].mobileAuthenticationEnabled.toString()}",
style: TextStyle(fontSize: 18),
),
SizedBox(
height: 10,
),
Text(
"Platform => ${snapshotData.devices[index].platform}",
style: TextStyle(fontSize: 18),
),
SizedBox(
height: 10,
),
],
);
},
)
: Center(
child: SizedBox(
child: CircularProgressIndicator(),
),
);
},
),
child: _buildDeviceInfoList(),
),
],
),
Expand Down
10 changes: 5 additions & 5 deletions ios/Classes/NativeBridge/Errors/SdkError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ class SdkError: Error {
}

// Error codes with httResponse information
init(code: Int, errorDescription: String, response: ONGResourceResponse?, iosCode: Int? = nil, iosMessage: String? = nil) {
init(code: Int, errorDescription: String, response: ResourceResponse?, iosCode: Int? = nil, iosMessage: String? = nil) {
self.code = code
self.errorDescription = errorDescription

setGenericDetails()
setResponseDetails(response, iosCode, iosMessage)
}

init(_ wrapperError: OneWelcomeWrapperError, response: ONGResourceResponse?, iosCode: Int? = nil, iosMessage: String? = nil) {
init(_ wrapperError: OneWelcomeWrapperError, response: ResourceResponse?, iosCode: Int? = nil, iosMessage: String? = nil) {
self.code = wrapperError.code()
self.errorDescription = wrapperError.message()

Expand Down Expand Up @@ -82,7 +82,7 @@ private extension SdkError {
}
}

func setResponseDetails(_ response: ONGResourceResponse?, _ iosCode: Int?, _ iosMessage: String?) {
func setResponseDetails(_ response: ResourceResponse?, _ iosCode: Int?, _ iosMessage: String?) {
if response == nil {
details["response"] = [String: Any?]()
} else {
Expand All @@ -100,11 +100,11 @@ private extension SdkError {
}
}

private extension ONGResourceResponse {
private extension ResourceResponse {
func toJSON() -> [String: Any?] {
return ["statusCode": statusCode,
"headers": allHeaderFields,
"url": rawResponse.url?.absoluteString,
"url": response.url,
"body": data != nil ? String(data: data!, encoding: .utf8) : nil
]
}
Expand Down
Loading