A similar code is used in my «Facebook Login» Magento 2 extension.
See also:
How to add a custom attribute to an EAV entity type?
The standard EAV entity types