簡體   English   中英

Flutter:如何在兩個獨立的 android 應用程序之間安全地共享數據?

[英]Flutter: How to securely share data among two separate android apps?

我需要在 android 上的兩個獨立應用程序之間共享一些特定數據,最好制作某種只能由兩個應用程序訪問的共享文件夾。

為什么? 我需要兩個單獨的應用程序之間的單點登錄功能。

到目前為止,我一直在使用 JWT 令牌對用戶進行身份驗證,方法是將它們存儲在 sharedpreferences 中(存儲它們以維護登錄)並在用戶注銷時清除共享首選項(以及點擊更改令牌的 api)。

現在我有另一個使用相同令牌的應用程序。

需要什么:您登錄一個,另一個自動登錄。因此,我的計划是將令牌存儲在設備上,而這兩個應用程序都可以訪問該令牌。

我知道我需要一個活動目錄來實現安全的 SSO,但我可以接受目前還沒有 100% 的安全性,關於如何在應用程序之間共享數據的問題仍然存在。

我只是給你一個想法,更不用說這只適用於Android

  1. 從您的第一個應用程序(主要),使用path_provider在設備外部存儲中創建一個文件(現在,我正在創建一個 .txt 文件),

     Future<void> _createAndWrite() async { // Get external directory final directory = (await Directory('storage/emulated/0/Sharing Folder').create()).path; // Create your file final file = File('$directory/any_file.txt'); await file.create(); // Write to the file await file.writeAsString('Content to write'); }
  2. 在您的第二個應用程序中,您可以使用以下內容讀取文件的內容:

     Future<void> _readFile() async { // Get external directory final directory = (await Directory('storage/emulated/0/Sharing Folder').create()).path; // Get the file final file = File('$directory/any_file.txt'); // Read it final content = await file.readAsString(); }

確保在這兩個應用程序中都聲明了以下權限:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM