Configuring keychain sharing in a .NET MAUI iOS app - Stack Overflow

I have several old (objective c and swift) apps that use a shared keychain (for storing login informati

I have several old (objective c and swift) apps that use a shared keychain (for storing login information).

I am rewriting one of these older applications using .NET MAUI.

I am having problems accessing the shared keychain from the new MAUI app.

I have added an entitlements.plist (and registered this in my project). I have included the keychain access group value in this plist.

.csproj...

<CodesignEntitlements>Platforms/iOS/Entitlements.plist</CodesignEntitlements>

.plist...

<key>keychain-access-groups</key>
<array>
    <string>$(AppIdentifierPrefix)my-group-name</string>
</array>

I am signing the new MAUI app using a provisioning profile that uses the same seed (team id) as the older apps.

When I try to retrieve any value from a shared keychain using the following line of code...

var testValue = await SecureStorage.GetAsync("TestValue");

I then deploy the MAUI app to TestFlight and download to my iPad (the same way I did with the old apps)...

...To test if I can access the keychain, I write the keychain value to a label on the page. This is when I get a null value returned. I do not get any errors returned.

Note: The value is in use by the other applications so I know it exists.

Really stuck and would super appreciate any help or suggestions.

I have several old (objective c and swift) apps that use a shared keychain (for storing login information).

I am rewriting one of these older applications using .NET MAUI.

I am having problems accessing the shared keychain from the new MAUI app.

I have added an entitlements.plist (and registered this in my project). I have included the keychain access group value in this plist.

.csproj...

<CodesignEntitlements>Platforms/iOS/Entitlements.plist</CodesignEntitlements>

.plist...

<key>keychain-access-groups</key>
<array>
    <string>$(AppIdentifierPrefix)my-group-name</string>
</array>

I am signing the new MAUI app using a provisioning profile that uses the same seed (team id) as the older apps.

When I try to retrieve any value from a shared keychain using the following line of code...

var testValue = await SecureStorage.GetAsync("TestValue");

I then deploy the MAUI app to TestFlight and download to my iPad (the same way I did with the old apps)...

...To test if I can access the keychain, I write the keychain value to a label on the page. This is when I get a null value returned. I do not get any errors returned.

Note: The value is in use by the other applications so I know it exists.

Really stuck and would super appreciate any help or suggestions.

Share Improve this question edited Mar 21 at 15:29 Hilory 2,1417 gold badges14 silver badges30 bronze badges asked Mar 21 at 15:25 Jared HillJared Hill 211 silver badge5 bronze badges 1
  • There's no direct way to use keychain share for secure storage in MAUI. You may try implementing in a native way. You may try my suggestion below. – Felix Shen Commented Mar 27 at 7:12
Add a comment  | 

1 Answer 1

Reset to default 0

Maui Secure storage is used to store simple key/value pairs. To implement keychain sharing for Secure Storage, you may fire a feature request on GitHub for it.

Inspired by this PR Ability to set accessgroup on secure storage. Fixes, you may try implementing your own SecureStorage for iOS platform by invoking platform code.

For example, in Platforms/iOS folder, you can create new CustomSecureStorage class to replace SecureStorage class. You may consider this PR and try the code for the CustomSecureStorage class with some changes, e.g.,

you may customize the GetAsync method by adding a new accessGroup parameter as below,

    static Task<string> GetAsync(string key, string accessGroup)
    {
        if (string.IsNullOrWhiteSpace(key))
            throw new ArgumentNullException(nameof(key));


        var alias = GetAlias(accessGroup);
        var kc = new KeyChain(DefaultAccessible, accessGroup);
        var value = kc.ValueForKey(key, alias);

        return Task.FromResult(value);
    }

you may also customize the SetAsync or Remove method using your own logic.

After the implementation of CustomSecureStorage, you can consume CustomSecureStorage by invoking iOS platform code,

#if IOS
        var sc = new CustomSecureStorage();
        await SecureStorage.SetAsync("TestValue", "test","accessGroup");
        var testValue =new  CustomSecureStorage().GetAsync("TestValue","accessGroup");
#endif

Hope it helps!

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744343273a4569533.html

相关推荐

  • Configuring keychain sharing in a .NET MAUI iOS app - Stack Overflow

    I have several old (objective c and swift) apps that use a shared keychain (for storing login informati

    9天前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信