Skip to content

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

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 = "johndoe@yourtenant.onmicrosoft.com",
    PasswordProfile = new PasswordProfile
    {
        ForceChangePasswordNextSignIn = true,
        Password = "TempP@ssw0rd!"
    }
};

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

But don't require a password change!

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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