The Internet of Things technology is taking advantage of the advancements in hardware and software platforms for enabling new application domains like smart buildings and in a general sense, smart (indoor) environments. Some of the key requirements are security and flexibility. Access control plays an important role in granting access to resources like network and data storage and retrieval to devices joining the security domain. This article introduces a solution for enabling dynamic security domains in which devices join in a trustful way via an authentication framework. In the present paper we document the addressed use cases and requirements, the background technology evolution from 4G to 5G core network, together with the proposed solution and its results using a laboratory testbed.