Skip to content

[iOS] [issue] For Outlook personal accounts (imap) - Not expired silent access token, requested from background, is loosing lease/access to IMAP 1h after application start (beyond that 1h - background requested tokens do not work). #2334

Open
@Be-Maps

Description

@Be-Maps

I guess there should be an MSAL log entry with something for offline access (which I have in Azure in delegated permissions):
image

MSAL requests by default "openid profile offline_access" scopes. I was reading openid does not work for personal accounts - and maybe this makes it fail and not requests the offline_access.

I am not sure if my conclusions here are correct, but below is the behaviour I am seeing.

For delegated permissions for personal account I use scopes:
"https://outlook.office.com/IMAP.AccessAsUser.All",
"https://outlook.office.com/SMTP.Send"

I was trying to pass to MSAL offline_access in various ways , but MSAL does not take it, and I get error:
//"offline_access",
//"https://outlook.office.com/offline_access",
//"https://graph.microsoft.com/offline_access",
//"https://graph.microsoft.com/.default",
//".default",

In general I was using examples, and all started working until 1h passes:
https://cocoapods.org/pods/MSAL
https://learn.microsoft.com/de-de/graph/tutorials/ios-swift?tutorial-step=3

According to this Microsoft specification it should be possible to get access tokens and refresh tokens with silent token request:
https://learn.microsoft.com/pt-br/entra/identity-platform/v2-oauth2-auth-code-flow

Based on the articles below offline_access must be requested for mobile applications and possibly due to lack of that any tokens will be valid only for 1h from application start because offline_access was not requested, and because than refresh token is only granted 1h lifetime:
https://learn.microsoft.com/en-us/exchange/client-developer/legacy-protocols/how-to-authenticate-an-imap-pop-smtp-application-by-using-oauth
https://learn.microsoft.com/en-gb/entra/identity-platform/access-tokens

I can only see in the MSAL log following requested and returned (for interactive and silent requests):

MSAL log: TID=20301803 MSAL 1.3.2 iOS 17.5.1 [2024-09-09 16:37:48 - F2CC8655-27DC-4A1F-9772-BDF5B4B82013] [MSAL] -[MSALPublicClientApplication acquireTokenSilentForScopes:(
"https://outlook.office.com/IMAP.AccessAsUser.All",
"https://outlook.office.com/SMTP.Send"
)
account:Masked(not-null)
authority:<MSALAADAuthority: 0x301a1d060>
validateAuthority:Yes
forceRefresh:Yes
correlationId:(null)
capabilities:(null)
claimsRequest:(null)]

...
...
MSAL log: TID=20301801 MSAL 1.3.2 iOS 17.5.1 [2024-09-09 16:37:49 - F2CC8655-27DC-4A1F-9772-BDF5B4B82013] [MSAL] Silent flow finished. Result (not-null), error: 0 error domain: (null)
MSAL log: TID=20301801 MSAL 1.3.2 iOS 17.5.1 [2024-09-09 16:37:49] Parsing result access token
MSAL log: TID=20301801 MSAL 1.3.2 iOS 17.5.1 [2024-09-09 16:37:49 - F2CC8655-27DC-4A1F-9772-BDF5B4B82013] [MSAL] acquireTokenSilent returning with at: a754306 scopes:(
"https://outlook.office.com/IMAP.AccessAsUser.All",
"https://outlook.office.com/SMTP.Send"
) expiration:2024-09-09 17:37:49 +0000

Result:

  • After 1hour I am still getting tokens, but they are not allowing to IMAP login.
  • When I force refresh next token, valid longer than the 1h from app start, it works for IMAP until the 1h and stops to work even when it has 40min lifetime left.
  • tested it also from thread on background - strangely I get the token but it does not work at all (from beginning)

NOTE: Above is in debug mode - I guess debug mode does not limit the lifetime of tokens?

I also described the problem in: #2325

Please help.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions