MsalProvider not handling token expiration properly
还没有人认领这个 Issue。
评估
- 难度
- 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 文件
- 有 Pull Request 模板
- 没有贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 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
维护者通常 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 条评论 ·