douchenzhan3050 2019-02-01 23:16
浏览 395

如何将api(令牌)经过身份验证的用户(在flutter应用程序中)重定向到基于会话的身份验证(在扑动的Web视图中)?

What I want to achieve: let's say I have an Api (token) authenticated user then once this user click a button I wanted to open a web-view and authenticate him on a session based auth. enter image description here

What I did till now (many solutions and propositions):

  1. use url_launcher:

    • open a browser on click launch(url)
    • send a token (GET params) to the backend server
    • authenticate the user and redirect back Working well BUT bad Ux, user needs to go between browser and the app!
  2. use 1flutter_webview_plugin or 2webview_flutter:

    • open a webview on click 1

      class __WebWidget extends StatelessWidget {
       @override
       Widget build(BuildContext context) {
         return WebviewScaffold(
           url: url + "?token=${userManager.token}",
           appBar: new AppBar(
             title: Text('Space'),
           ),
           withZoom: true,
           withLocalStorage: true,
           hidden: true,
           initialChild: Container(
             color: Colors.blueAccent,
             child: const Center(
               child: Text('Loading....'),
             ),
           ),
         );
       }
      }
      

      2

      class WebWidget extends StatelessWidget {
        WebWidget({this.url});
      
        final String url;
      
        @override
        Widget build(BuildContext context) {
          return Scaffold(
            appBar: AppBar(
              title: Text('Votre Espace '),
            ),
            body: WebView(
              initialUrl: url + "?token=${userManager.token}",
              javascriptMode: JavascriptMode.unrestricted,
            ),
          );
        }
      }
      ```
      
    • send a token (GET params) to the backend server

    • authenticate the user and redirect back Not Working !

I suspected that the webview does not support the cookies !

In the backend, i'm using laravel (php7) and Apache server.

thanks in advance

  • 写回答

1条回答 默认 最新

  • dsjmrpym220113739 2019-05-21 15:12
    关注

    Since you're using flutter, I'd recommend the Flutter Web Auth plugin for authenticating a user with a web service. It can be used for any web flow that can redirect to a custom scheme.

    It automatically redirects you to your app with authenticated tokens (If your app is Android then remember to edit the AndroidManifest.xml as per the instructions given in the README.md file)

    评论

报告相同问题?

悬赏问题

  • ¥50 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?