Aplikasi web yang memasukkan pengguna: Pendaftaran aplikasi

Artikel ini menjelaskan langkah-langkah pendaftaran aplikasi untuk aplikasi web yang memasukkan pengguna.

Untuk mendaftarkan aplikasi, Anda dapat menggunakan:

  • Aplikasi mulai cepat web. Selain menjadi pengalaman pertama yang hebat dalam pembuatan aplikasi, mulai cepat di portal Microsoft Azure memiliki tombol bernama Buat perubahan ini untuk saya. Anda dapat menggunakan tombol ini untuk mengatur properti yang Anda butuhkan, bahkan untuk aplikasi yang ada. Menyesuaikan nilai properti ini untuk kasus Anda sendiri. Secara khusus, URL API web untuk aplikasi Anda mungkin akan berbeda dari default yang diusulkan, yang juga akan memengaruhi URI keluar.
  • Portal Microsoft Azure untuk mendaftarkan aplikasi secara manual.
  • PowerShell dan alat baris perintah.

Mendaftarkan aplikasi dengan menggunakan mulai cepat

Anda dapat menggunakan tautan berikut untuk bootstrap pembuatan aplikasi web Anda:

Daftarkan aplikasi

Mendaftarkan aplikasi dengan menggunakan portal Microsoft Azure

Tip

Langkah-langkah dalam artikel ini mungkin sedikit berbeda berdasarkan portal tempat Anda memulai.

Catatan

Portal yang digunakan berbeda tergantung pada jika aplikasi Anda berjalan di cloud publik Microsoft Azure atau dalam cloud nasional atau sovereign cloud. Untuk informasi selengkapnya, lihat Cloud nasional.

  1. Masuk ke Pusat Admin Microsoft Entra.
  2. Jika Anda memiliki akses ke beberapa penyewa, gunakan ikon Pengaturan di menu atas untuk beralih ke penyewa tempat Anda ingin mendaftarkan aplikasi dari menu Direktori + langganan.
  3. Telusuri ke Aplikasi> Identitas>Pendaftaran aplikasi, pilih Pendaftaran baru.
  1. Saat halaman Daftarkan aplikasi muncul, masukkan informasi pendaftaran aplikasi Anda:
    1. Masukkan Nama untuk aplikasi Anda, contohnya AspNetCore-WebApp. Pengguna aplikasi mungkin melihat nama ini, dan Anda dapat mengubahnya nanti.
    2. Pilih Jenis akun yang didukung untuk aplikasi. (Lihat jenis akun yang didukung.)
    3. Untuk URI pengalihan, tambahkan jenis aplikasi dan tujuan URI yang akan menerima respons token yang dihasilkan setelah autentikasi berhasil. Misalnya, masukkan https://localhost:44321.
    4. Pilih Daftarkan.
  2. Di bawah Kelola, pilih Autentikasi lalu tambahkan informasi berikut:
    1. Di bagian Web, tambahkan https://localhost:44321/signin-oidc sebagai URI Pengalihan.
    2. Untuk URL keluar dari saluran depan, masukkan https://localhost:44321/signout-oidc.
    3. Di bawah Pemberian implisit dan alur hibrid, pilih token ID.
    4. Pilih Simpan.

Mendaftarkan aplikasi menggunakan PowerShell

Anda juga dapat mendaftarkan aplikasi dengan Microsoft Graph PowerShell, menggunakan New-MgApplication.

Berikut adalah ide kode. Untuk kode yang berfungsi penuh, lihat sampel ini

# 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)"

Langkah selanjutnya

Beralih ke artikel berikutnya dalam skenario ini, Konfigurasi kode aplikasi.