MsalProvider not handling token expiration properly
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 35/100
- issue の種類
- バグ
- 明瞭さ
- おおむね明確
- 活発さ
- 停滞
- 技術スタック
- csharp
調査の方向性
MsalProvider とその GetTokenWithScopesAsync メソッドから始め、再現手順に記載されているトークン取得フローを追ってください。トークンの有効期限が切れた後にリクエストを再現し、アカウントの選択を要求せずに、すでに認証されているアカウントが再利用されることを確認してください。
索引モデルが issue の本文から書いたものです。
説明
Describe the bug
My app periodically check for files in OneDrive and i've notices that if the app is kept opened long enough, the token will expire and the user will be prompt to select an account again.
I've manage to work around this issue by creating my own MsalProvider and changing the GetTokenWithScopesAsync as follows:
protected async Task<string> GetTokenWithScopesAsync(string[] scopes, bool silentOnly = false)
{
await SemaphoreSlim.WaitAsync();
try
{
AuthenticationResult authResult = null;
try
{
var account = Account ?? (await Client.GetAccountsAsync()).FirstOrDefault();
if (account != null)
{
authResult = await Client.AcquireTokenSilent(scopes, account).ExecuteAsync();
}
}
catch (MsalUiRequiredException)
{
// CODE ADDED TO WORK AROUND THE EXPIRATION TOKEN ISSUE
if (Account != null)
{
Account = null;
SemaphoreSlim.Release();
return await GetTokenWithScopesAsync(scopes, silentOnly);
}
}
catch
{
// Unexpected exception
// TODO: Send exception to a logger.
}
if (authResult == null && !silentOnly)
{
try
{
var paramBuilder = Client.AcquireTokenInteractive(scopes);
if (Account != null)
{
paramBuilder = paramBuilder.WithAccount(Account);
}
paramBuilder = paramBuilder.WithPrompt(Microsoft.Identity.Client.Prompt.NoPrompt);
authResult = await paramBuilder.ExecuteAsync();
}
catch
{
// Unexpected exception
// TODO: Send exception to a logger.
}
}
Account = authResult?.Account;
return authResult?.AccessToken;
}
finally
{
SemaphoreSlim.Release();
}
}
I'm not submitting this as a PR cause i think that this is not the best way to handle this issue.
Steps to Reproduce
Steps to reproduce the behavior:
- Open an app and make a request so that a token is generated
- Keep the app open until the token expires
- Try to make another request
- The app will prompt you to select an account again.
Expected behavior
I believe that once the user has authenticated the account selection window should not be prompt again.
Environment
Package Version(s): 7.1.1
Windows 11 Build Number:
- [x] Windows 11 (22000)
App min and target version:
- [ ] Fall Creators Update (16299)
- [ ] April 2018 Update (17134)
- [ ] October 2018 Update (17763)
- [x] May 2019 Update (18362)
- [x] Windows 11 (Build 22000)
Device form factor:
- [x] Desktop
- [ ] Xbox
- [ ] Surface Hub
- [ ] IoT
Visual Studio
- [ ] 2017 (version: )
- [ ] 2019 (version: )
- [ ] 2019 Preview (version: )
- [x] 2022
- 主要言語
- C#
- スター
- 156
- フォーク
- 37
- PR マージ指標
- 30日以内にマージされた PR はありません
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドなし
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
CommunityToolkit/Graph-Controls のほかの issue
-
bug :bug:
難易度 4/5 3〜5日 初心者へのやさしさ 25/100
CommunityToolkit/Graph-Controls#211 · コメント 3 件 ·
-
CommunityToolkit.Authentication.Msal use Microsoft Graph V4 but if you install V5,you cannot releaseオープンbug :bug: needs attention :wave: needs triage :mag:
難易度 4/5 3〜5日 初心者へのやさしさ 25/100
CommunityToolkit/Graph-Controls#208 · コメント 20 件 ·
-
enhancement :sparkles:
難易度 2/5 1〜3時間 初心者へのやさしさ 35/100
-
Area: Providers
難易度 2/5 1〜3時間 初心者へのやさしさ 55/100
CommunityToolkit/Graph-Controls#195 · コメント 1 件 ·
-
Area: Providers documentation :page_with_curl: question :grey_question:
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
CommunityToolkit/Graph-Controls#188 · コメント 6 件 ·
CommunityToolkit/Graph-Controls の issue をすべて見る
似ている issue
-
area: core bug help wanted ready
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
ZaidX88/sluice#265 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
area: remote bug
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
メンテナーはふだん 1 日以内に返信
-
📅 Sprint 4 Module-Tools Setup Submit:None 🦔 Size Tiny
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
CodeYourFuture/Module-Tools#712 ·
-
A: Mapping P3: Standard T: New Feature
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
space-wizards/space-station-14#46878 · コメント 2 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 半日 初心者へのやさしさ 60/100
CommunityToolkit/Windows#896 · コメント 2 件 ·