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)

    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog