Advertisement
Beginner .NET MAUI, Security & Authentication

How do you store authentication tokens securely in MAUI?

Short answer

Use SecureStorage, which encrypts values with the platform keystore/keychain, for tokens and secrets. Never keep them in Preferences (plain) or in source. Clear tokens on logout with SecureStorage.Default.Remove or RemoveAll.

Save .NET MAUI mock interview
Advertisement
AModel answer
Use SecureStorage, which encrypts values with the platform keystore/keychain, for tokens and secrets. Never keep them in Preferences (plain) or in source. Clear tokens on logout with SecureStorage.Default.Remove or RemoveAll.
await SecureStorage.Default.SetAsync("refresh_token", token);
SecureStorage.Default.Remove("refresh_token");   // on logout
Real-world example
After sign-in the refresh token lives in the OS keychain and is wiped on logout.
Likely follow-ups
  • Why not Preferences for tokens? | How do you clear on logout?
Related topics