Advertisement
Guest User

Untitled

a guest
Jun 6th, 2022
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.90 KB | None | 0 0
  1. final Completer<WebViewController> _webViewController =
  2. Completer<WebViewController>();
  3.  
  4. Widget getWebView() {
  5. var url = "https://$_userPool" +
  6. ".amazoncognito.com/oauth2/authorize?identity_provider=Google&redirect_uri=" +
  7. "myapp://&response_type=CODE&client_id=$clientId" +
  8. "&scope=email%20openid%20profile%20aws.cognito.signin.user.admin";
  9. return WebView(
  10. initialUrl: url,
  11. userAgent: 'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) ' +
  12. 'AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Mobile Safari/537.36',
  13. javascriptMode: JavascriptMode.unrestricted,
  14. onWebViewCreated: (WebViewController webViewController) {
  15. _webViewController.complete(webViewController);
  16. },
  17. navigationDelegate: (NavigationRequest request) {
  18. if (request.url.startsWith("myapp://?code=")) {
  19. String code = request.url.substring("myapp://?code=".length);
  20. signUserInWithAuthCode(code);
  21. return NavigationDecision.prevent;
  22. }
  23.  
  24. return NavigationDecision.navigate;
  25. },
  26. gestureNavigationEnabled: true,
  27. );
  28. }
  29.  
  30. Future signUserInWithAuthCode(String authCode) async {
  31. String url = "https://$_userPool" +
  32. ".amazoncognito.com/oauth2/token?grant_type=authorization_code&client_id=" +
  33. "$clientId&code=" +
  34. authCode +
  35. "&redirect_uri=myapp://";
  36. final response = await http.post(Uri.parse(url),
  37. body: {},
  38. headers: {'Content-Type': 'application/x-www-form-urlencoded'});
  39. if (response.statusCode != 200) {
  40. throw Exception("Received bad status code from Cognito for auth code:" +
  41. response.statusCode.toString() +
  42. "; body: " +
  43. response.body);
  44. }
  45. }
  46.  
  47.  
  48. now inside sign in with google button
  49.  
  50. GestureDetector(
  51. onTap: () {
  52. provider.getWebView;
  53. },
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement