MsalProvider not handling token expiration properly
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Anfängerfreundlichkeit
- 35/100
- Issue-Typ
- Bug
- Klarheit
- Größtenteils klar
- Aktivitätsstatus
- Veraltet
- Tech-Stack
- csharp
- Bereich
- authentication
Rechercherichtung
Beginne mit MsalProvider und seiner Methode GetTokenWithScopesAsync und verfolge dann den in den Reproduktionsschritten beschriebenen Ablauf der Tokenbeschaffung. Führe eine Anfrage nach Ablauf des Tokens erneut aus und überprüfe, dass ein bereits authentifiziertes Konto wiederverwendet wird, ohne zur Auswahl eines Kontos aufzufordern.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
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
- Vorherrschende Sprache
- C#
- Sterne
- 156
- Forks
- 37
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Entwicklungsumgebung
- Kein Dockerfile und keine Docker-Compose-Datei
- Hat eine Pull-Request-Vorlage
- Kein Beitragsleitfaden
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus CommunityToolkit/Graph-Controls
-
bug :bug:
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 25/100
CommunityToolkit/Graph-Controls#211 · 3 Kommentare ·
-
CommunityToolkit.Authentication.Msal use Microsoft Graph V4 but if you install V5,you cannot releaseOffenbug :bug: needs attention :wave: needs triage :mag:
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 25/100
CommunityToolkit/Graph-Controls#208 · 20 Kommentare ·
-
enhancement :sparkles:
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 35/100
-
Area: Providers
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 55/100
CommunityToolkit/Graph-Controls#195 · 1 Kommentar ·
-
Area: Providers documentation :page_with_curl: question :grey_question:
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 35/100
CommunityToolkit/Graph-Controls#188 · 6 Kommentare ·
Alle Issues in CommunityToolkit/Graph-Controls
Ähnliche Issues
-
area: core bug help wanted ready
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 62/100
ZaidX88/sluice#265 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
area: remote bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100
Maintainer antworten meist innerhalb von 1 Tag
-
Install a C# EnvironmentOffen📅 Sprint 4 Module-Tools Setup Submit:None 🦔 Size Tiny
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 70/100
CodeYourFuture/Module-Tools#712 ·
-
A: Mapping P3: Standard T: New Feature
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100
space-wizards/space-station-14#46878 · 2 Kommentare ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 Ein halber Tag Anfängerfreundlichkeit 60/100
CommunityToolkit/Windows#896 · 2 Kommentare ·