-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Integrate data sharing UI for registration flow
1. Integrate this endpoint for now - https://staging-consent-bb-iam.igrant.io/realms/3pp-application/protocol/openid-connect/auth?client_id=3pp&response_type=code&redirect_uri=https%3A%2F%2Fstaging-consent-bb-api.igrant.io%2Fv2%2Fservice%2Fdata-sharing%3FdataAgreementId%3D654cf0db9684ed907ce07c5f%26thirdPartyOrgName%3DData4Diabetes%26dataSharingUiRedirectUrl%3Dhttps%3A%2F%2Fwww.govstack.global%2F 2. Call the optInToDataAgreement function exposed by privacy dashboard.
- Loading branch information
1 parent
86a418e
commit c84521c
Showing
12 changed files
with
582 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
lib/app/modules/dataSharing/binding/dataAgreement_binding.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
|
||
import 'package:Data4Diabetes/app/modules/dataSharing/controllers/dataAgreement_controller.dart'; | ||
import 'package:get/get.dart'; | ||
import 'package:get/get_instance/src/bindings_interface.dart'; | ||
|
||
class DataAgreementBinding extends Bindings { | ||
@override | ||
void dependencies() { | ||
Get.lazyPut<DataAgreementContoller>( | ||
() => DataAgreementContoller(), | ||
fenix: true, | ||
); | ||
|
||
|
||
} | ||
} |
206 changes: 206 additions & 0 deletions
206
lib/app/modules/dataSharing/controllers/dataAgreement_controller.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,206 @@ | ||
import 'dart:convert'; | ||
import 'dart:ui'; | ||
|
||
import 'package:Data4Diabetes/app/core/base/base_controller.dart'; | ||
import 'package:Data4Diabetes/app/modules/Register/controllers/register_controller.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter/services.dart'; | ||
import 'package:get/get.dart'; | ||
import 'package:shared_preferences/shared_preferences.dart'; | ||
import 'package:webview_flutter/webview_flutter.dart'; | ||
|
||
import '../../login/views/login_view.dart'; | ||
|
||
class DataAgreementContoller extends BaseController { | ||
final RegisterController _registerController = Get.find(); | ||
WebViewController? controller; | ||
var platform = const MethodChannel('io.igrant.data4diabetes.channel'); | ||
var dataAgreementId = "654cf0db9684ed907ce07c5"; | ||
|
||
var thirdPartyOrgName = "Data4Diabetes"; | ||
String? accessToken; | ||
var redirectUrl = "https://www.govstack.global/"; | ||
// invokeDataAgreement() { | ||
// controller = WebViewController() | ||
// ..setJavaScriptMode(JavaScriptMode.unrestricted) | ||
// ..setBackgroundColor(const Color(0x00000000)) | ||
// ..setNavigationDelegate( | ||
// NavigationDelegate( | ||
// onProgress: (int progress) { | ||
// // if (progress != maxProgressValue) { | ||
// // showLoading(); | ||
// // } else { | ||
// // hideLoading(); | ||
// // } | ||
// | ||
// return; | ||
// }, | ||
// onPageStarted: (String url) { | ||
// /// show progress on loading | ||
// // showLoading(); | ||
// | ||
// return; | ||
// }, | ||
// onPageFinished: (String url) { | ||
// /// stop progress after loading | ||
// // hideLoading(); | ||
// | ||
// return; | ||
// }, | ||
// onWebResourceError: (WebResourceError error) { | ||
// return; | ||
// }, | ||
// onNavigationRequest: (NavigationRequest request) async { | ||
// if (request.url.startsWith('https://www.govstack.global/')) { | ||
// final uri = Uri.parse(request.url); | ||
// print('the response uri:${uri.queryParameters}'); | ||
// if (uri.queryParameters.containsKey('error')) { | ||
// // Handle error response | ||
// String? error = uri.queryParameters['error']; | ||
// String? errorDescription = uri.queryParameters['errorDescription']; | ||
// print('Error: $error, Description: $errorDescription'); | ||
// GetSnackToast(message: errorDescription??"something went wrong"); | ||
// Get.off(LoginView()); | ||
// } else if (uri.queryParameters.containsKey('credentials')) { | ||
// // Decode the base64-encoded credentials | ||
// print('got scueess data'); | ||
// String? credentialsBase64 = uri.queryParameters['credentials']; | ||
// // Ensure that the base64 string has the correct length and padding | ||
// String paddedCredentialsBase64 = credentialsBase64! + '=' * (4 - credentialsBase64.length % 4); | ||
// | ||
// // Decode the padded base64 string | ||
// List<int> bytes = base64.decode(paddedCredentialsBase64); | ||
// String decodedCredentialsJson = utf8.decode(bytes); | ||
// | ||
// Map<String, dynamic> decodedCredentials = json.decode(decodedCredentialsJson); | ||
// | ||
// // Accessing user information | ||
// Map<String, dynamic> userInfo = decodedCredentials['userInfo']; | ||
// String subject = userInfo['subject']; | ||
// String email = userInfo['email']; | ||
// bool emailVerified = userInfo['emailVerified']; | ||
// | ||
// print('Subject: $subject'); | ||
// print('Email: $email'); | ||
// print('Email Verified: $emailVerified'); | ||
// | ||
// // Accessing token information | ||
// Map<String, dynamic> token = decodedCredentials['token']; | ||
// String accessToken = token['accessToken']; | ||
// int expiresIn = token['expiresIn']; | ||
// String refreshToken = token['refreshToken']; | ||
// | ||
// print('Access Token: $accessToken'); | ||
// print('Expires In: $expiresIn'); | ||
// print('Refresh Token: $refreshToken'); | ||
// | ||
// SharedPreferences _prefs = await SharedPreferences.getInstance(); | ||
// await _prefs.setString('dataSharingAccessToken',accessToken ); | ||
// await _prefs.setInt('dataSharingTokenExpiresIn',expiresIn ); | ||
// await _prefs.setString('dataSharingRefreshToken',refreshToken ); | ||
// Get.back(); | ||
// int index = _registerController.selectedPage.value + 1; | ||
// _registerController.pageController.animateToPage(index, | ||
// duration: const Duration(milliseconds: 500), | ||
// curve: Curves.ease); | ||
// | ||
// | ||
// GetSnackToast(message: 'Authorized successfully',color: Colors.green); | ||
// } | ||
// | ||
// return NavigationDecision.navigate; | ||
// } | ||
// | ||
// return NavigationDecision.navigate; | ||
// }, | ||
// ), | ||
// ) | ||
// ..loadRequest(Uri.parse( | ||
// 'https://staging-consent-bb-iam.igrant.io/realms/3pp-application/protocol/openid-connect/auth?client_id=3pp&response_type=code&redirect_uri=https%3A%2F%2Fstaging-consent-bb-api.igrant.io%2Fv2%2Fservice%2Fdata-sharing%3FdataAgreementId%3D654cf0db9684ed907ce07c5f%26thirdPartyOrgName%3DData4Diabetes%26dataSharingUiRedirectUrl%3Dhttps%3A%2F%2Fwww.govstack.global%2F')); | ||
// } | ||
|
||
invokeDataAgreement() { | ||
controller = WebViewController() | ||
..setJavaScriptMode(JavaScriptMode.unrestricted) | ||
..setBackgroundColor(const Color(0x00000000)) | ||
..setNavigationDelegate( | ||
NavigationDelegate( | ||
onProgress: (int progress) { | ||
return; | ||
}, | ||
onPageStarted: (String url) { | ||
/// show progress on loading | ||
return; | ||
}, | ||
onPageFinished: (String url) { | ||
/// stop progress after loading | ||
return; | ||
}, | ||
onWebResourceError: (WebResourceError error) { | ||
return; | ||
}, | ||
onNavigationRequest: (NavigationRequest request) async { | ||
if (request.url.startsWith(redirectUrl)) { | ||
final uri = Uri.parse(request.url); | ||
if (uri.queryParameters.containsKey('error')) { | ||
// Handle error response | ||
String? error = uri.queryParameters['error']; | ||
String? errorDescription = | ||
uri.queryParameters['errorDescription']; | ||
GetSnackToast( | ||
message: errorDescription ?? "something went wrong"); | ||
Get.off(LoginView()); | ||
_registerController.firstNameController.clear(); | ||
_registerController.mobileNumberController.clear(); | ||
} else if (uri.queryParameters.containsKey('credentials')) { | ||
// Decode the base64-encoded credentials | ||
String? credentialsBase64 = uri.queryParameters['credentials']; | ||
// Ensure that the base64 string has the correct length and padding | ||
String paddedCredentialsBase64 = credentialsBase64! + | ||
'=' * (4 - credentialsBase64.length % 4); | ||
// Decode the padded base64 string | ||
List<int> bytes = base64.decode(paddedCredentialsBase64); | ||
String decodedCredentialsJson = utf8.decode(bytes); | ||
Map<String, dynamic> decodedCredentials = | ||
json.decode(decodedCredentialsJson); | ||
// Accessing user information | ||
// Map<String, dynamic> userInfo = decodedCredentials['userInfo']; | ||
// String subject = userInfo['subject']; | ||
// String email = userInfo['email']; | ||
// bool emailVerified = userInfo['emailVerified']; | ||
// Accessing token information | ||
Map<String, dynamic> token = decodedCredentials['token']; | ||
accessToken = token['accessToken']; | ||
// int expiresIn = token['expiresIn']; | ||
// String refreshToken = token['refreshToken']; | ||
SharedPreferences _prefs = | ||
await SharedPreferences.getInstance(); | ||
await _prefs.setString('dataSharingAccessToken', accessToken!); | ||
var response = await platform.invokeMethod('DataSharing', { | ||
"accessToken": token, | ||
"dataAgreementID": "65530f3507a0b7e06bdd9383", | ||
"baseUrl": "https://staging-consent-bb-api.igrant.io/v2/" | ||
}); | ||
Map<String, dynamic> responseMap = json.decode(response); | ||
if (responseMap['optIn'] == true) { | ||
Get.back(); | ||
int index = _registerController.selectedPage.value + 1; | ||
_registerController.pageController.animateToPage(index, | ||
duration: const Duration(milliseconds: 500), | ||
curve: Curves.ease); | ||
} else { | ||
GetSnackToast(message: 'something went wrong'); | ||
} | ||
} | ||
|
||
return NavigationDecision.navigate; | ||
} | ||
|
||
return NavigationDecision.navigate; | ||
}, | ||
), | ||
) | ||
..loadRequest(Uri.parse( | ||
'https://staging-consent-bb-iam.igrant.io/realms/3pp-application/protocol/openid-connect/auth?client_id=3pp&response_type=code&redirect_uri=https%3A%2F%2Fstaging-consent-bb-api.igrant.io%2Fv2%2Fservice%2Fdata-sharing%3FdataAgreementId%3D654cf0db9684ed907ce07c5f%26thirdPartyOrgName%3DData4Diabetes%26dataSharingUiRedirectUrl%3Dhttps%3A%2F%2Fwww.govstack.global%2F')); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
|
||
|
||
import 'package:Data4Diabetes/app/modules/dataSharing/controllers/dataAgreement_controller.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:get/get.dart'; | ||
import 'package:webview_flutter/webview_flutter.dart'; | ||
|
||
import '../../../Constants/Palette.dart'; | ||
import '../../../core/base/base_view.dart'; | ||
|
||
class DataAgreementView extends BaseView<DataAgreementContoller> { | ||
@override | ||
PreferredSizeWidget? appBar(BuildContext context) { | ||
return AppBar( | ||
backgroundColor: Colors.transparent, | ||
//centerTitle: true, | ||
elevation: 0, | ||
automaticallyImplyLeading: true, | ||
leading: IconButton( | ||
onPressed: (){ | ||
Get.back(); | ||
}, | ||
icon: const Icon(Icons.arrow_back_ios), | ||
), | ||
); | ||
} | ||
final DataAgreementContoller _dataAgreementContoller = Get.find(); | ||
@override | ||
Widget body(BuildContext context) { | ||
return FutureBuilder<String>( | ||
future:_dataAgreementContoller. invokeDataAgreement(), | ||
builder: (BuildContext context, snapshot) { | ||
if (snapshot.connectionState == ConnectionState.waiting) { | ||
// Display a loading spinner while waiting for the future to complete | ||
return Center(child: CircularProgressIndicator()); | ||
} else if (snapshot.hasError) { | ||
// Display an error message if the future throws an error | ||
return Text('Error: ${snapshot.error}'); | ||
} else { | ||
// Display the fetched data | ||
return WebViewWidget(controller:_dataAgreementContoller. controller!); | ||
} | ||
}, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.