Hi,
What you are trying to achieve is a valid use case, but the challenge you are facing comes from how the EmailConnector module is designed. Out of the box, it is primarily built with an admin-driven setup in mind, and the entities involved (such as Account, OAuth configuration, tokens, etc.) are typically restricted to admin roles. Exposing this directly to end users without adjusting security will lead to the kind of illegal access issues you are seeing.
A clean way to approach this is to introduce a controlled abstraction layer instead of exposing the EmailConnector entities directly.
First, avoid giving end users direct access to the EmailConnector domain model. Instead, create your own entity (for example, UserMailbox) that is associated with Account (or the relevant EmailConnector entity). This allows you to manage ownership (per user) while keeping EmailConnector internals protected.
Second, handle the OAuth flow via a microflow or nanoflow that runs with elevated privileges (for example, using a microflow with “Apply entity access = false” or a dedicated admin/helper microflow). The idea is that the user triggers the action (clicks “Add Account”), but the actual creation and linking of the EmailConnector Account and OAuth tokens happens in a controlled server-side flow with sufficient rights.
Third, the illegal access error you mentioned (which disappears after refresh) is typically caused by object access mismatch within the same request. This often happens when:
To resolve this:
Fourth, make sure your security model is aligned:
Finally, for the user experience (button → authorize → select account), you can:
In summary, the key is not to expose EmailConnector entities directly to end users, but to wrap them in your own domain model and handle all sensitive operations through controlled microflows with proper security boundaries. This avoids illegal access issues and gives you full control over the user experience without modifying the core module.