/// <summary> /// Internal method to get a user attribute value, while checking if this attribute is readable /// </summary> /// <param name="user">The user to retrieve the attribute for.</param> /// <param name="attributeName">The attribute to retrieve.</param> /// <returns></returns> private async Task <string> GetAttributeValueAsync(TUser user, string attributeName, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); if (user.Attributes == null) { throw new ArgumentException("user.Attributes must be initialized."); } var clientConfig = await _pool.GetUserPoolClientConfiguration().ConfigureAwait(false); if (!clientConfig.ReadAttributes.Contains(attributeName)) { throw new NotAuthorizedException(string.Format("Reading attribute {0} is not allowed by the user pool client configuration.", attributeName)); } // There is an edge case where an attribute might be there in the pool configuration, but not on the user profile if (user.Attributes.ContainsKey(attributeName)) { return(user.Attributes[attributeName]); } else { return(null); } }
/// <summary> /// Internal method to get a user attribute value, while checking if this attribute is readable /// </summary> /// <param name="user">The user to retrieve the attribute for.</param> /// <param name="attributeName">The attribute to retrieve.</param> /// <returns></returns> private async Task <string> GetAttributeValueAsync(TUser user, string attributeName, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); if (user.Attributes == null) { throw new ArgumentException("user.Attributes must be initialized."); } var clientConfig = await _pool.GetUserPoolClientConfiguration().ConfigureAwait(false); if (!clientConfig.ReadAttributes.Contains(attributeName)) { throw new NotAuthorizedException(string.Format("Reading attribute {0} is not allowed by the user pool client configuration.", attributeName)); } // This throws a KeyNotFoundException if the attribute name does not exist in the dictionnary. return(user.Attributes[attributeName]); }