Hello Vesa,
Thank you for reaching out to Microsoft Q&A.
This is not a secure or robust approach. It introduces the risk of tampering and could lead to unexpected behavior. CSS or JavaScript to hide fields that shouldn't be collected from the user is not recommended.
Instead of hiding input fields with CSS/JavaScript, a better approach would be to not include the claim in the user flow at all. If a claim is not meant to be set by the user, it should not be part of the user flow. You can use API connectors to set these claims programmatically without relying on user input.
You are correct that you don't need to have a claim included in the user flow in order to set it via an API connector. The claims that are part of the user flow (those visible to the user) are primarily for gathering user input. However, an API connector can return values for any claim, including ones that are not explicitly part of the user flow.
As you mentioned, you have confirmed through experimentation that even if a claim is not selected in the user flow, you can still make a Graph API request to set that property for the user. This behavior suggests that the user flow attributes are just about customizing the UI and don't necessarily define the entire set of attributes that can be managed in the B2C tenant's directory.
About API connectors in Azure AD B2C | Microsoft Learn
These API connectors can only be used to alter the sign-up part of a sign up and sign in or sign-up user flows.
These API connectors cannot be used to:
add claims to a token during sign in
add additional information not collected from the user to the user information stored in the directory
API connectors allow to specify an APIs endpoint to call from a user flow. The request and response to the API endpoint are strictly defined: we send information in a certain format and expect it in a certain format. This will often entail the user developing an Azure Function or other web API service to accept and respond to API calls.
At this time, only 'Basic authentication' of the API call is supported. See https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication#basic_authentication_scheme to learn more about basic auth. A customer has to specify basic auth - API calls can't be unauthenticated. If they don't want to implement basic auth, then they can pass 'dummy' username and password that their API can just ignore.
All API calls are of the HTTP 'POST' method.
I hope this clarifies things.