Skip to content
This repository has been archived by the owner on Jun 30, 2023. It is now read-only.

Failed to save ADAL cache record after incorporating intune SDK into Xamarin iOS #1625

Closed
1 of 4 tasks
amt-work opened this issue Jul 2, 2019 · 24 comments
Closed
1 of 4 tasks
Assignees

Comments

@amt-work
Copy link

amt-work commented Jul 2, 2019

Which Version of ADAL are you using ?
ADAL 5.1.0, intune SDK 11.0.8

Which platform has the issue?
Xamarin iOS

What authentication flow has the issue?

  • Mobile
    • Interactive
    • Integrated Windows Auth
    • Username Password
    • Device code flow (browserless)
      (iOS is using broker)

Is this a new or existing app?
The app is in production, and I have upgraded to a new version of ADAL and attempted to add in the intune SDK.

Repro
Similar issue: #1601
Similar issue: #1611

The issue is occurring when I am attempting to add the intune SDK to an existing application that has ADAL incorporated into it. When adding the line: authContext.iOSKeychainSecurityGroup = "com.microsoft.msalrocks" my app is no longer able to cache tokens. Removing this line allows it to do so, however this line seems to be needed in order to make the intune SDK work correctly. I am logging in with username and password, not using authenticator.

Expected behavior
App should store the token in the cache

Actual behavior
App is not storing the token in the cache. The call to authContext.AcquireTokenAsync(...), is returning a token but not caching it, returning the result "Failed to save adal cache record".

@jennyf19
Copy link
Contributor

jennyf19 commented Jul 2, 2019

@amt-work Are you using com.microsoft.adalcache as the value for the iOSKeychainSecurityGroup? You need that value in the entitlements as well.

@amt-work
Copy link
Author

amt-work commented Jul 2, 2019

@jennyf19 Yes, I'm setting it like this: authContext.iOSKeychainSecurityGroup = "com.microsoft.adalcache"; in my entitlements file I have $(AppIdentifierPrefix)com.microsoft.adalcache

@jennyf19
Copy link
Contributor

jennyf19 commented Jul 2, 2019

@amt-work Thanks for confirming.
Can you send the ADAL logs for a failed request, and can you get the Intune incident ID as well? Do you have a link to your code or a repro?

cc: @Kyle-Reis

@amt-work
Copy link
Author

amt-work commented Jul 2, 2019

@jennyf19 The logs look like when I do the first authContext.AcquireTokenAsync(...):
AdalLoggerBase.cs: ADAL PCL.iOS with assembly version '5.1.0.0', file version '5.1.0.0' and informational version '5.1.0' is running...
AdalLoggerBase.cs: === Token Acquisition started:
CacheType: MicrosoftIdentityModel.Clients.ActiveDirectory.TokenCache (0 items)
Authentication Target: User
, Authority Host: login.microsoftonline.com
AdalLoggerBase.cs: Loading from Cache.

AdalLoggerBase.cs: Looking up cache for a token...
AdalLoggerBase.cs: No matching token was found in the cache
AdalLoggerBase.cs: Checking MSAL cache for user token cache
AdalLoggerBase.cs: A match was found in the MSAL cache ? False
(repeats this 6 times)
AdalLoggerBase.cs: Either a token was not found or an exception was thrown.
-canOpenUrl: failed for URL: "msauth://" - error: "The operation couldn't be completed. (OSStatus error -10814.)"
AdalLoggerBase.cs: iOS Broker can be invoked.
AdalLoggerBase.cs: Cannot involed the broker directly, may require install...
AdalLoggerBase.cs: Check and AcquireToken using broker
AdalLoggerBase.cs: Broker invocation is NOT required.
AdalLoggerBase.cs: Storing token in the cache...
AdalLoggerBase.cs: An item was stored in the cache
AdalLoggerBase.cs: Serializing token cache with 1 items.
AdalLoggerBase.cs: Failed to remove adal cache record:
AdalLoggerBase.cs: Failed to save adal cache record:
AdalLoggerBase.cs: === Token Acquisition finished successfully. An access token was returned:

Then when I call authContext.AcquireTokenSilentAsync(...) I get this:
AdalLoggerBase.cs: Clearing Cache :- 0 items to be removed
AdalLoggerBase.cs: Successfully Cleared Cache
AdalLoggerBase.cs: Serializing token cache with 0 items.
AdalLoggerBase.cs: Failed to remove adal cache record:
AdalLoggerBase.cs: Failed to save adal cache record:

I'm not sure what the intune incident ID is and I can't post my code because its private.

@jennyf19
Copy link
Contributor

jennyf19 commented Jul 2, 2019

@amt-work any chance you can enable pii and send me those logs via email? or, if you can tell me the SecStatusCode coming back from "Failed to save adal cache record:" that would be helpful. [email protected]

@amt-work
Copy link
Author

amt-work commented Jul 2, 2019

@jennyf19 I'm not sure how to retrieve the SecStatusCode. What I posted is all the logs returned back to me.

@jennyf19
Copy link
Contributor

jennyf19 commented Jul 2, 2019

@amt-work Sorry it wasn't clear, if you enable pii logs, you will get back the SecStatusCode as part of the error message.

@jennyf19
Copy link
Contributor

@amt-work @biozal ...is this still an issue?

@amt-work
Copy link
Author

@jennyf19 I put this feature on hold temporarily so I haven't had a chance to look at it since then.

@jmprieur
Copy link
Contributor

@amt-work can you please check with the latest version. We think it's fixed
#catsarecool

@amt-work
Copy link
Author

@jmprieur latest version of ADAL package or latest version of intune SDK?

@jmprieur
Copy link
Contributor

@amt-work : sorry, I was not clear. Of ADAL.

@amt-work
Copy link
Author

@jmprieur I actually still have this issue, even after updating my ADAL version and the intune SDK version. For reference, the pii logs state: AdalLoggerBase.cs: Failed to save adal cache record: MissingEntitlement, I'm unsure what entitlement it's referring to specifically. I haven't touched this since July but it's the same issue I was having then.

@jennyf19
Copy link
Contributor

@amt-work you need to set up the entitlements and use the iOSKeychainSecurityGroup property

Entitlements should look like this:

<dict>
  <key>keychain-access-groups</key>
  <array>
    <string>$(AppIdentifierPrefix)com.microsoft.adalcache</string>
  </array>
</dict>
</plist>

@amt-work
Copy link
Author

amt-work commented Nov 15, 2019

@jennyf19 My entitlements.plist file contains this:

 	<key>keychain-access-groups</key>
 	<array>
		<string>$(AppIdentifierPrefix)temp.company.name</string>
 		<string>$(AppIdentifierPrefix)com.microsoft.adalcache</string>
 		<string>$(AppIdentifierPrefix)com.microsoft.azureauthenticator</string>
 		<string>$(AppIdentifierPrefix)com.azure.authenticator</string>
		<string>$(AppIdentifierPrefix)com.microsoft.intune.mam</string>
</array>

And my iOSKeychainSecurityGroup looks like this:

var authContext = new AuthenticationContext(authority);
 authContext.iOSKeychainSecurityGroup = "com.microsoft.adalcache";

@ghost
Copy link

ghost commented Nov 16, 2019 via email

@jennyf19
Copy link
Contributor

@amt-work did you make sure it's also configured here:

Can you provide logs? you can send them via email if that is easier ([email protected])

@jennyf19
Copy link
Contributor

thanks @biozal

@amt-work
Copy link
Author

@biozal @jennyf19 yeah I do have my entitlements file selected, where is the intune build tool located?

@ghost
Copy link

ghost commented Nov 18, 2019 via email

@Kyle-Reis
Copy link

Actually, with the latest version of the Intune Xamarin.iOS bindings (12.0.12), setting the iOSKeychainSecurityGroup property should no longer be required.

@Kyle-Reis
Copy link

The IntuneMAMConfigurator should be getting run at build time automatically, and if there is no entitlements file associated with the configuration you’re building, it should result in a build error. Does your project contain multiple entitlements files specific to config (debug/release) or target (simulator/device)? If so could you ensure the entitlements file for the specific configuration you’re building contains the required keychain access groups?

@jennyf19
Copy link
Contributor

@Kyle-Reis @biozal Thanks for the updates.

fyi: @amt-work

@amt-work
Copy link
Author

@Kyle-Reis @biozal @jennyf19 I only have 1 entitlements file for all my configurations. I don't use a custom entitlements file usually, only for this. I also just ran the intunemamconfigurator tool with my plist and entitlements file, my files didn't get changed at all and I got the "Success!!!" result.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants