示例#1
0
        internal static MsalAccountCacheItem FromJObject(JObject j)
        {
            var item = new MsalAccountCacheItem
            {
                PreferredUsername = JsonUtils.ExtractExistingOrEmptyString(j, StorageJsonKeys.Username),
                Name           = JsonUtils.ExtractExistingOrEmptyString(j, StorageJsonKeys.Name),
                GivenName      = JsonUtils.ExtractExistingOrEmptyString(j, StorageJsonKeys.GivenName),
                FamilyName     = JsonUtils.ExtractExistingOrEmptyString(j, StorageJsonKeys.FamilyName),
                LocalAccountId = JsonUtils.ExtractExistingOrEmptyString(j, StorageJsonKeys.LocalAccountId),
                AuthorityType  = JsonUtils.ExtractExistingOrEmptyString(j, StorageJsonKeys.AuthorityType),
                TenantId       = JsonUtils.ExtractExistingOrEmptyString(j, StorageJsonKeys.Realm),
            };

            item.PopulateFieldsFromJObject(j);

            return(item);
        }
示例#2
0
        internal static CacheSerializationContract FromJsonString(string json)
        {
            JObject root        = JObject.Parse(json);
            var     unkownNodes = ExtractUnkownNodes(root);

            var contract = new CacheSerializationContract(unkownNodes);

            // Access Tokens
            if (root.ContainsKey(StorageJsonValues.CredentialTypeAccessToken))
            {
                foreach (var token in root[StorageJsonValues.CredentialTypeAccessToken]
                         .Values())
                {
                    if (token is JObject j)
                    {
                        var item = MsalAccessTokenCacheItem.FromJObject(j);
                        contract.AccessTokens[item.GetKey().ToString()] = item;
                    }
                }
            }

            // Refresh Tokens
            if (root.ContainsKey(StorageJsonValues.CredentialTypeRefreshToken))
            {
                foreach (var token in root[StorageJsonValues.CredentialTypeRefreshToken]
                         .Values())
                {
                    if (token is JObject j)
                    {
                        var item = MsalRefreshTokenCacheItem.FromJObject(j);
                        contract.RefreshTokens[item.GetKey().ToString()] = item;
                    }
                }
            }

            // Id Tokens
            if (root.ContainsKey(StorageJsonValues.CredentialTypeIdToken))
            {
                foreach (var token in root[StorageJsonValues.CredentialTypeIdToken]
                         .Values())
                {
                    if (token is JObject j)
                    {
                        var item = MsalIdTokenCacheItem.FromJObject(j);
                        contract.IdTokens[item.GetKey().ToString()] = item;
                    }
                }
            }

            // Accounts
            if (root.ContainsKey(StorageJsonValues.AccountRootKey))
            {
                foreach (var token in root[StorageJsonValues.AccountRootKey]
                         .Values())
                {
                    if (token is JObject j)
                    {
                        var item = MsalAccountCacheItem.FromJObject(j);
                        contract.Accounts[item.GetKey().ToString()] = item;
                    }
                }
            }

            // App Metadata
            if (root.ContainsKey(StorageJsonValues.AppMetadata))
            {
                foreach (var token in root[StorageJsonValues.AppMetadata]
                         .Values())
                {
                    if (token is JObject j)
                    {
                        var item = MsalAppMetadataCacheItem.FromJObject(j);
                        contract.AppMetadata[item.GetKey().ToString()] = item;
                    }
                }
            }

            return(contract);
        }