Skip to content
  • English Deutsch

benjamin-abt.com

Performance is a feature | Cloud - AI - Azure - .NET - Sustainability

  • Home
  • Blog
  • Portfolio
    • Overview
    • Workshops & Training
    • Publications
  • Contact
  • Home
  • Blog

Create an Entra Local User Account via Microsoft Graph with .NET

Create an Entra Local User Account via Microsoft Graph with .NET
February 4, 2025 3 min read BEN ABT
Csharp .NET Microsoftgraph Microsoft Entra ID

The Microsoft Graph and Entra documentation are both very comprehensive and provide a lot of information - but they often contain no examples or no working examples. In addition, the SDKs are either not, insufficiently or incorrectly documented.

In this article, I will show you how to create a local user in Entra External Identities with Microsoft Graph - and this example even works!

Requirements

  • You are using the Microsoft.Graph NuGet package, currently version 5.69.0.

Necessary information

  • You need your tenant domain (either mydomain.onmicrosoft.com or a custom domain like mydomain.com)

Basically, using an Entra Local account means that you are primarily responsible for the administration. And although the documentation tells you that certain values are set automatically, you have to do this yourself. The SDK is simply incorrectly documented here - as is unfortunately so often the case.

Creation of the user principal name

The User Principal Name (UPN) is the unique identification of a user in your tenant. It basically consists of the user name and the domain. With an external user, however, you do not have a user name and have to think of something yourself. The domain is mandatory and must correspond to the domain of your tenant (e.g. mydomain.onmicrosoft.com). Something the SDK could have done for you, but good SDKs are unfortunately in short supply. For the user name, I make it easy for myself and use a prefix together with the UserId that the user has(will have in the database in my system.

The format therefore corresponds to user_<userid>@<domain>
At the end it looks like user_25e54711-a403-4290-a47e-d228ff7beb28@mydomain.onmicrosoft.com

This allows me to link the entry in Entra with the entry in the database at any time (for example to cleanup corrupt entries). The user itself is later linked to the Entra Object Id in the database, as recommended by Microsoft.

Creating a user

The actual creation of the user is simple if you know what you need. Even if the SDK tells you that property XYZ has to be set, but property X does not - absolute nonsense. You are bombarded with useless error messages.

What works is the following minimal setup:

C#
 1// inputs
 2Guid userId = ...
 3string emailAddress = ...
 4string password = ...
 5
 6// create new user object
 7string newUpn = $"user_{userId}@{options.TenantDomain}";
 8
 9User newUser = new()
10{
11    AccountEnabled = false, // enable this, if you want
12    DisplayName = emailAddress,
13
14    PasswordPolicies = "DisablePasswordExpiration,DisableStrongPassword", // remove this, if you want
15    PasswordProfile = new PasswordProfile
16    {
17        ForceChangePasswordNextSignIn = false,
18        Password = password
19    },
20
21    // Local User - all properties are required
22    CreationType = "LocalAccount",
23    UserType = "Member",
24    UserPrincipalName = newUpn,
25    Identities =
26    [
27        new() {
28            SignInType = "emailAddress",
29            Issuer = _clientContext.Domain,
30            IssuerAssignedId = emailAddress
31        }
32    ]
33};

This setup…

  • … creates a local user with a password
  • … the password policies for expiration and password rules are disabled (we don’t want expiration and we have slightly customized rules for Entra - but you can just leave both enabled if you want)
  • … the account is initially deactivated (as the user must first validate their e-mail address, after which the account is activated)
  • … the user name is generated from the e-mail address
  • … the user is created as LocalAccount, which is a fixed value - as is the UserType Member,
  • … the login takes place via the e-mail address, which we pass as emailAddress.
  • … the Issuer is the domain of your tenant

Actually, creating a local user in Entra External Identities is not that difficult - if you know which values you have to set with which content. Maybe one day we will get a great Graph SDK and a useful documentation :-)

Related articles

Containerizing .NET in 2026 Without a Dockerfile

Oct 20, 2026 - 11 min read

Containerizing .NET in 2026 Without a Dockerfile

Most .NET Dockerfiles repeat the same five steps: restore, publish, select the matching Microsoft runtime image, copy the output and start …

Problem Details in ASP.NET Core and .NET 11

Oct 5, 2026 - 12 min read

Problem Details in ASP.NET Core and .NET 11

builder.Services.AddProblemDetails() registers infrastructure. It does not create an error contract. An ASP.NET Core request can fail during …

Resilience in .NET with Microsoft.Extensions.Resilience

Sep 21, 2026 - 11 min read

Resilience in .NET with Microsoft.Extensions.Resilience

Retries are the most visible resilience strategy and the easiest one to misuse. Repeating a failing call can recover from a short network …


BEN ABT

BEN ABT

Ben is Chief Engineering Officer and Principal Software Engineer at Medialesson.de, with a strong focus on .NET and Microsoft Azure. In his professional role, he designs and builds highly scalable platforms for hybrid and cloud-based scenarios. He also advises companies and C-levels on migrating to the sovereign cloud.

He runs myCSharp.de, the largest and most active German-speaking C# community forum, actively contributes to both his own and external open-source projects and regularly shares his knowledge through his blog, at community events, conferences and as a writer for technical magazines.

Let's Work Together

Looking for an experienced Platform Architect or Engineer for your next project? Whether it's cloud migration, platform modernization or building new solutions from scratch - I'm here to help you succeed.

New Platforms

Modernization

Training & Consulting

Contact Me
X Facebook LinkedIn WhatsApp
Back Next Blog Post

Open for work!

Contact Me
BEN ABT BEN ABT Software Engineer · Microsoft MVP Passionate about .NET, Azure, performance optimization and sustainable software engineering.

Medialesson GmbH Logo

Microsoft MVP Logo

Recent posts

View all
Stop Using nginx as Your Default Static File Server in Docker

Stop Using nginx as Your Default Static File Server in …

Oct 24, 2026
Containerizing .NET in 2026 Without a Dockerfile

Containerizing .NET in 2026 Without a Dockerfile

Oct 20, 2026
Problem Details in ASP.NET Core and .NET 11

Problem Details in ASP.NET Core and .NET 11

Oct 5, 2026
Resilience in .NET with Microsoft.Extensions.Resilience

Resilience in .NET with Microsoft.Extensions.Resilience

Sep 21, 2026
What Matters in ASP.NET Core 11

What Matters in ASP.NET Core 11

Sep 14, 2026

Tags

.NET (192) Csharp (96) ASP.NET Core (48) Azure (41) DevOps (17) Docker (14) Microsoft (14) EF Core (11) Microsoft MVP (11) AI (10) GitHub (10) GitHub Copilot (10) ASP.NET (9) Security (9) Synology (9) Architecture (8) Raspberry (8) Azure Functions (7) Cloudflare (7) Bicep (6)
benjamin-abt.com

About BEN

Benjamin Abt is a Software Engineer, Platform Architect and Microsoft MVP specializing in .NET, Azure, cloud architecture, performance optimization and sustainable software development.

Connect

  • Follow me on GitHub
  • Follow me on LinkedIn
  • Follow me on Mastodon
  • Microsoft MVP profile
  • Follow SchwabenCode on GitHub
  • Follow me on X

Quick Links

  • Portfolio
  • Blog
  • Workshops & Training
  • Publications
  • Get in Touch
  • Sitemap
Open for Work

© Copyright Benjamin Abt & SchwabenCode | 2011 - 2026

Content licensed under CC BY 4.0 unless otherwise noted.

  • Impressum
  • Privacy
  • Contact