簡體   English   中英

msal+oauth - 如何從 android/flutter 檢索刷新令牌

[英]msal+oauth - how to retrieve refresh token from android/flutter

我們正在開發一個應用程序,它可以預見多個使用 oauth 登錄的 Microsoft 帳戶。 我們正在使用這個 package

https://pub.dev/packages/msal_mobile#-readme-tab-

它包裝了官方的微軟庫

https://github.com/AzureAD/microsoft-authentication-library-for-android

我知道該庫不會直接公開刷新令牌,而是在后端刷新它。 但是,因為 flutter 庫不允許多個登錄帳戶(最終因為用戶可能從相關的 Microsoft 帳戶在 Internet 上退出,因此也從應用程序中退出他的帳戶之一)我們需要交換訪問權限使用如下請求的帶有刷新令牌的令牌:

POST /common/oauth2/v2.0/token HTTP/1.1 Host: https://login.microsoftonline.com Content-Type: application/x-www-form-urlencoded 
client_id=...
&scope=...    &code=OAAABAAAAiL9Kn2Z27UubvWFPbm0gLWQJVzCTE9UkP3pSx1aXxUjq3n8b2JRLk4OxVXr...
&redirect_uri=msauth://...
 &grant_type=authorization_code

但是,為了這樣做,我收到一個錯誤“ invalid_grant" ,描述如下:

> "AADSTS9002313: Invalid request. Request is malformed or invalid...”

而提供的 accessToken 似乎是正確的,並且它由 msal/flutter 庫正確返回。 我們如何解決這個問題? 該應用程序似乎已在 azure 門戶網站上正確設置。 如果這是 android 官方 msal 庫的限制,您是否有任何提示如何添加該功能? 謝謝(托馬斯)

I don't know too much about flutter, but if I remember correctly, for azure oauth, if you are trying to get a refresh token using the token endpoint, then you must request the scope of offline_access with that authorization_code grant type. 也許試試看。

暫無
暫無

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

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