Skip to content

Allow anonymous access by programmatically creating a user with AADB2C #266

@christiannagel

Description

@christiannagel
  • with the users API, add an API to create a new user with an anon-xx username with B2C
  • add this option to the Blazor client
  • create background functionality to cleanup non-active anon users when not active for TBD days

This should be possible with Graph (CoPilot):

using Microsoft.Graph;
using Microsoft.Identity.Client;

var clientId = "YOUR_CLIENT_ID";
var clientSecret = "YOUR_CLIENT_SECRET";
var tenantId = "YOUR_TENANT_ID";

IConfidentialClientApplication confidentialClientApplication = ConfidentialClientApplicationBuilder
    .Create(clientId)
    .WithTenantId(tenantId)
    .WithClientSecret(clientSecret)
    .Build();

ClientCredentialProvider authProvider = new ClientCredentialProvider(confidentialClientApplication);
GraphServiceClient graphClient = new GraphServiceClient(authProvider);
var user = new User
{
    AccountEnabled = true,
    DisplayName = "John Doe",
    MailNickname = "johndoe",
    UserPrincipalName = "[email protected]",
    PasswordProfile = new PasswordProfile
    {
        ForceChangePasswordNextSignIn = true,
        Password = "TempP@ssw0rd!"
    }
};

await graphClient.Users
    .Request()
    .AddAsync(user);

But don't require a password change!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions