Application web qui connecte les utilisateurs : Inscription d'application

Cette article explique les spécificités de l’inscription d’application pour une application web qui connecte des utilisateurs.

Pour inscrire votre application, vous pouvez utiliser les méthodes suivantes :

  • Démarrages rapides d’application web. En plus d’être une excellente première expérience pour la création d’une application, les démarrages rapides du Portail Azure contiennent un bouton nommé Apporter cette modification pour moi. Vous pouvez utiliser ce bouton pour définir les propriétés dont vous avez besoin, même pour une application existante. Adaptez les valeurs de ces propriétés à votre propre cas. En particulier, l’URL de l’API web pour votre application sera probablement différente de celle proposée par défaut, ce qui influera également sur l’URI de déconnexion.
  • Portail Azure pour inscrire votre application manuellement.
  • PowerShell et outils en ligne de commande

Inscrire une application en utilisant les démarrages rapides

Vous pouvez utiliser le lien suivant pour démarrer la création de votre application web :

Inscrire une application

Inscrire une application à l’aide du Portail Azure

Conseil

Les étapes décrites dans cet article peuvent varier légèrement en fonction du portail de départ.

Remarque

Le portail à utiliser est différent selon que votre application s’exécute dans le cloud public Microsoft Azure ou dans un cloud national ou souverain. Pour plus d’informations, voir Clouds nationaux

  1. Connectez-vous au centre d’administration Microsoft Entra.
  2. Si vous avez accès à plusieurs tenants, utilisez l’icône Paramètres dans le menu supérieur pour basculer vers le tenant dans lequel vous voulez inscrire l’application à partir du menu Répertoires + abonnements.
  3. Accédez à Identité>Applications>Inscriptions d’applications, puis sélectionnez Nouvelle inscription.
  1. Lorsque la page Inscrire une application s’affiche, saisissez les informations d’inscription de votre application :
    1. Entrez un nom pour votre application (par exemple, AspNetCore-WebApp). Les utilisateurs de votre application peuvent voir ce nom, et vous pouvez le changer ultérieurement.
    2. Sélectionnez les types de comptes pris en charge par votre application. (Consultez Types de comptes pris en charge.)
    3. Dans URI de redirection, ajoutez le type d’application et la destination d’URI qui acceptera les réponses de jeton retournées après une authentification réussie. Par exemple, entrez https://localhost:44321.
    4. Sélectionnez Inscrire.
  2. Sous Gérer, sélectionnez Authentification, puis ajoutez les informations suivantes :
    1. Dans la section Web, ajoutez https://localhost:44321/signin-oidc comme URI de redirection.
    2. Dans l’adresse URL de déconnexion du canal frontal, entrez https://localhost:44321/signout-oidc.
    3. Sous Octroi implicite et flux hybrides, sélectionnez Jetons d’ID.
    4. Cliquez sur Enregistrer.

Inscrire une application à l’aide de PowerShell

Vous pouvez également inscrire une application avec Microsoft Graph PowerShell, à l’aide de New-MgApplication.

Voici une idée du code. Pour obtenir un code entièrement fonctionnel, consultez cet exemple

# Connect to the Microsoft Graph API, non-interactive is not supported for the moment (Oct 2021)
Write-Host "Connecting to Microsoft Graph"
if ($tenantId -eq "") {
   Connect-MgGraph -Scopes "User.Read.All Organization.Read.All Application.ReadWrite.All" -Environment $azureEnvironmentName
}
else {
   Connect-MgGraph -TenantId $tenantId -Scopes "User.Read.All Organization.Read.All Application.ReadWrite.All" -Environment $azureEnvironmentName
}
   
$context = Get-MgContext
$tenantId = $context.TenantId

# Get the user running the script
$currentUserPrincipalName = $context.Account
$user = Get-MgUser -Filter "UserPrincipalName eq '$($context.Account)'"

# get the tenant we signed in to
$Tenant = Get-MgOrganization
$tenantName = $Tenant.DisplayName
   
$verifiedDomain = $Tenant.VerifiedDomains | where {$_.Isdefault -eq $true}
$verifiedDomainName = $verifiedDomain.Name
$tenantId = $Tenant.Id

Write-Host ("Connected to Tenant {0} ({1}) as account '{2}'. Domain is '{3}'" -f  $Tenant.DisplayName, $Tenant.Id, $currentUserPrincipalName, $verifiedDomainName)

# Create the webApp AAD application
Write-Host "Creating the AAD application (WebApp)"
# create the application 
$webAppAadApplication = New-MgApplication -DisplayName "WebApp" `
                                                   -Web `
                                                   @{ `
                                                         RedirectUris = "https://localhost:44321/", "https://localhost:44321/signin-oidc"; `
                                                         HomePageUrl = "https://localhost:44321/"; `
                                                         LogoutUrl = "https://localhost:44321/signout-oidc"; `
                                                      } `
                                                      -SignInAudience AzureADandPersonalMicrosoftAccount `
                                                   #end of command

$currentAppId = $webAppAadApplication.AppId
$currentAppObjectId = $webAppAadApplication.Id

$tenantName = (Get-MgApplication -ApplicationId $currentAppObjectId).PublisherDomain
#Update-MgApplication -ApplicationId $currentAppObjectId -IdentifierUris @("https://$tenantName/WebApp")
   
# create the service principal of the newly created application     
$webAppServicePrincipal = New-MgServicePrincipal -AppId $currentAppId -Tags {WindowsAzureActiveDirectoryIntegratedApp}

# add the user running the script as an app owner if needed
$owner = Get-MgApplicationOwner -ApplicationId $currentAppObjectId
if ($owner -eq $null)
{
   New-MgApplicationOwnerByRef -ApplicationId $currentAppObjectId  -BodyParameter = @{"@odata.id" = "htps://graph.microsoft.com/v1.0/directoryObjects/$user.ObjectId"}
   Write-Host "'$($user.UserPrincipalName)' added as an application owner to app '$($webAppServicePrincipal.DisplayName)'"
}
Write-Host "Done creating the webApp application (WebApp)"

Étapes suivantes

Passez à l’article suivant de ce scénario, Configuration du code de l’application.