Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- final Completer<WebViewController> _webViewController =
- Completer<WebViewController>();
- Widget getWebView() {
- var url = "https://$_userPool" +
- ".amazoncognito.com/oauth2/authorize?identity_provider=Google&redirect_uri=" +
- "myapp://&response_type=CODE&client_id=$clientId" +
- "&scope=email%20openid%20profile%20aws.cognito.signin.user.admin";
- return WebView(
- initialUrl: url,
- userAgent: 'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) ' +
- 'AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Mobile Safari/537.36',
- javascriptMode: JavascriptMode.unrestricted,
- onWebViewCreated: (WebViewController webViewController) {
- _webViewController.complete(webViewController);
- },
- navigationDelegate: (NavigationRequest request) {
- if (request.url.startsWith("myapp://?code=")) {
- String code = request.url.substring("myapp://?code=".length);
- signUserInWithAuthCode(code);
- return NavigationDecision.prevent;
- }
- return NavigationDecision.navigate;
- },
- gestureNavigationEnabled: true,
- );
- }
- Future signUserInWithAuthCode(String authCode) async {
- String url = "https://$_userPool" +
- ".amazoncognito.com/oauth2/token?grant_type=authorization_code&client_id=" +
- "$clientId&code=" +
- authCode +
- "&redirect_uri=myapp://";
- final response = await http.post(Uri.parse(url),
- body: {},
- headers: {'Content-Type': 'application/x-www-form-urlencoded'});
- if (response.statusCode != 200) {
- throw Exception("Received bad status code from Cognito for auth code:" +
- response.statusCode.toString() +
- "; body: " +
- response.body);
- }
- }
- now inside sign in with google button
- GestureDetector(
- onTap: () {
- provider.getWebView;
- },
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement