Répondre

1

Vous pouvez utiliser l'API graphique pour créer une application dans votre répertoire. Voici le script PowerShell.

# Adding the AD library to your PowerShell Session. 
Add-Type -Path 'C:\Program Files\Microsoft Azure Active Directory Connect\Microsoft.IdentityModel.Clients.ActiveDirectory.dll' 

# This is the tenant id of you Azure AD. You can use tenant name instead if you want. 
$tenantID = "<your tenant id>" 
$authString = "https://login.microsoftonline.com/$tenantID" 

# Here, the username must be a user in your organization and with MFA disabled. 
# And, it must have permission to create an AD application. 
$username = "<your username>" 
$password = "<the password of your username>" 

# The resource URI for your token. 
$resource = "https://graph.windows.net" 

# This is the common client id. 
$client_id = "1950a258-227b-4e31-a9cf-717495945fc2" 

# Create a client credential with the above common client id, username and password. 
$creds = New-Object "Microsoft.IdentityModel.Clients.ActiveDirectory.UserCredential" ` 
     -ArgumentList $username,$password 

# Create a authentication context with the above authentication string. 
$authContext = New-Object "Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext" ` 
     -ArgumentList $authString 

# Acquire access token from server. 
$authenticationResult = $authContext.AcquireToken($resource,$client_id,$creds) 

# Use the access token to setup headers for your http request. 
$authHeader = $authenticationResult.AccessTokenType + " " + $authenticationResult.AccessToken 
$headers = @{"Authorization"=$authHeader; "Content-Type"="application/json"} 

# Send a request to create a new AD application. 
Invoke-RestMethod -Method POST ` 
    -Uri "https://graph.chinacloudapi.cn/$tenantID/applications?api-version=1.6-internal" ` 
    -Headers $headers -InFile ./application.json 

Si vous « Microsoft.IdentityModel.Clients.ActiveDirectory.dll » est dans un endroit différent, vous devez modifier le chemin de Add-Type.

Dans "application.json", vous devez spécifier les paramètres de votre application. Voici un échantillon simple.

{ 
    "odata.type": "Microsoft.DirectoryServices.Application", 
    "objectType": "Application", 
    "deletionTimestamp": null, 
    "allowActAsForAllClients": null, 
    "appBranding": null, 
    "appCategory": null, 
    "appData": null, 
    "appMetadata": { 
    "version": 0, 
    "data": [] 
    }, 
    "appRoles": [], 
    "availableToOtherTenants": false, 
    "displayName": "nativeClient", 
    "encryptedMsiApplicationSecret": null, 
    "errorUrl": null, 
    "groupMembershipClaims": null, 
    "homepage": null, 
    "identifierUris": [], 
    "keyCredentials": [], 
    "knownClientApplications": [], 
    "logoUrl": null, 
    "logoutUrl": null, 
    "oauth2AllowImplicitFlow": false, 
    "oauth2AllowUrlPathMatching": false, 
    "oauth2Permissions": [], 
    "oauth2RequirePostResponse": false, 
    "passwordCredentials": [], 
    "publicClient": true, 
    "recordConsentConditions": null, 
    "replyUrls": [ 
    "http://www.microsoft.com" 
    ], 
    "requiredResourceAccess": [ 
    { 
     "resourceAppId": "00000002-0000-0000-c000-000000000000", 
     "resourceAccess": [ 
     { 
      "id": "311a71cc-e848-46a1-bdf8-97ff7156d8e6", 
      "type": "Scope" 
     } 
     ] 
    } 
    ], 
    "samlMetadataUrl": null, 
    "supportsConvergence": false 
} 

Le « requiredResourceAccess » doit être réglé exactement comme ci-dessus, sinon votre application ne sera pas gérable par Azure portail classique. Si vous jetez un coup d'œil au fichier Json, vous découvrirez que l'application native et l'application Web partagent la même API et les mêmes propriétés. Tant que vous conservez la plupart des champs de la même manière que l'exemple ci-dessus, Azure créera une application native pour vous. Mais, bien sûr, vous pouvez modifier displayName et replyUrls.