These scripts are intended for developer and admin use during setup or environment provisioning.
They automate the registration process to ensure consistency across environments.
These scripts automate the creation of Ejento MS SSO and SharePoint Connection Azure AD app registrations using only the Azure CLI. They handle login, app creation, service principal creation, permission setup, and client secret generation automatically.Developers can run the scripts below to register the applications in their Azure tenant:
Common Requirements#
Dependencies#
Azure CLI installed and added to PATH Sign in to the correct Azure tenant:az login --use-device-code
Tenant setting:
Ensure that App registrations are allowed in your tenant:Go to: Entra ID → User settings → “Users can register applications” → Set to Yes
Role Requirements (Minimum)#
| Action | Required Role |
|---|
| Create app registrations, service principals, and client secrets | Application Administrator, Cloud Application Administrator, or Global Administrator |
| Grant tenant-wide admin consent | Global Administrator or Privileged Role Administrator |
The SSO script attempts to grant admin consent automatically.
If your account lacks the required role, a warning is logged.
You can manually approve it later:
Entra ID → Enterprise Applications → [App Name] → Permissions → Grant admin consent
How to Run the Scripts#
1.
Open any text editor and paste the desired script (SSO or SharePoint).
2.
Save the file with a meaningful name:sharepoint_app.ps1 → SharePoint script
3.
Open PowerShell in the same directory as the script.
Log you into Azure (if not already logged in)
Create the application and service principal
Generate and display the client secret
Save details (Tenant ID, Client ID, Secret, etc.) into a JSON file in the same directory
Register SSO Application#
Important Notes:#
The redirect URI will be updated later and provided by the Ejento team.
Admin consent must be granted if not already done.
Script: sso_app.ps1#
$ErrorActionPreference = "Stop"
if (-not (Get-Command az -ErrorAction SilentlyContinue)) {
Write-Error "Azure CLI (az) not found. Install from https://aka.ms/installazurecli and re-run."
exit 1
}
try {
$account = az account show --only-show-errors | ConvertFrom-Json
} catch {
az login --use-device-code | Out-Null
$account = az account show --only-show-errors | ConvertFrom-Json
}
$tenantId = $account.tenantId
$displayName = "ejento-ms-sso-$((Get-Random -Minimum 1000 -Maximum 9999))"
$redirectUri = "http://localhost:8000/oauth2/callback"
$graphAppId = "00000003-0000-0000-c000-000000000000"
$userReadAllRoleId = "df021288-bdef-4463-88db-98f22de89214"
$reqRes = @{
requiredResourceAccess = @(
@{
resourceAppId = $graphAppId
resourceAccess = @(
@{ id = $userReadAllRoleId; type = "Role" }
)
}
)
} | ConvertTo-Json -Depth 5
$optClaims = @{
accessToken = @(
@{ name = "email" },
@{ name = "family_name" },
@{ name = "given_name" }
)
} | ConvertTo-Json -Depth 5
$reqResFile = New-TemporaryFile
$optClaimsFile = New-TemporaryFile
Set-Content -Path $reqResFile -Value $reqRes -Encoding UTF8
Set-Content -Path $optClaimsFile -Value $optClaims -Encoding UTF8
Write-Host "`nCreating MS SSO App Registration..." -ForegroundColor Cyan
$appRaw = az ad app create `
--display-name $displayName `
--sign-in-audience AzureADMultipleOrgs `
--web-redirect-uris $redirectUri `
--enable-id-token-issuance true `
--enable-access-token-issuance true `
--required-resource-accesses "@$reqResFile" `
--optional-claims "@$optClaimsFile" `
--only-show-errors
$app = $appRaw | ConvertFrom-Json
$appId = $app.appId
$appObjectId = $app.id
Write-Host "Creating Service Principal..." -ForegroundColor Cyan
$spRaw = az ad sp create --id $appId --only-show-errors
$sp = $spRaw | ConvertFrom-Json
Write-Host "Granting Admin Consent (if permissions allow)..." -ForegroundColor Cyan
try {
az ad app permission admin-consent --id $appId --only-show-errors | Out-Null
} catch {
Write-Warning "Admin consent failed or requires Global Admin. You can grant later in Entra ID > Enterprise Applications > $displayName > Permissions."
}
Write-Host "Creating 1-year client secret..." -ForegroundColor Cyan
$credRaw = az ad app credential reset `
--id $appId `
--display-name "ms-sso-secret" `
--years 1 `
--only-show-errors
$cred = $credRaw | ConvertFrom-Json
$clientSecret = $cred.password
$result = [pscustomobject]@{
ApplicationName = $displayName
TenantId = $tenantId
ClientId = $appId
ClientObjectId = $appObjectId
ServicePrincipalObjectId = $sp.id
RedirectUri = $redirectUri
GrantedAppPermission = "Microsoft Graph: User.Read.All (Application)"
ClientSecret = $clientSecret
SecretExpiresOn = $cred.endDate
}
Write-Host "`n=== MS SSO App Created ===" -ForegroundColor Green
$result | Format-List
$outFile = "ms-sso-output.json"
$result | ConvertTo-Json -Depth 5 | Set-Content -Path $outFile -Encoding UTF8
Write-Host "`nSaved credentials summary to $outFile" -ForegroundColor Yellow
Write-Host "IMPORTANT: Store the ClientSecret securely. It cannot be retrieved later." -ForegroundColor Red
Register SharePoint Connection Application#
Important Notes:#
The redirect URI will be updated later and provided by the Ejento team.
Admin consent must be granted if not already done.
Script: sharepoint_app.ps1#
$ErrorActionPreference = "Stop"
if (-not (Get-Command az -ErrorAction SilentlyContinue)) {
Write-Error "Azure CLI not found. Install from https://aka.ms/installazurecli"
exit 1
}
try {
$account = az account show --only-show-errors | ConvertFrom-Json
} catch {
az login --use-device-code | Out-Null
$account = az account show --only-show-errors | ConvertFrom-Json
}
$tenantId = $account.tenantId
$displayName = "sharepointapp-$((Get-Random -Minimum 1000 -Maximum 9999))"
$redirectUri = "http://localhost:8000/oauth2/callback"
$graphAppId = "00000003-0000-0000-c000-000000000000"
$scopes = @{
"Files.ReadWrite.All" = "863451e7-0667-486c-a5d6-d135439485f0"
"Sites.ReadWrite.All" = "89fe6a52-be36-487e-b7d8-d061c450a026"
"offline_access" = "7427e0e9-2fba-42fe-b0c0-848c9e6a8182"
"User.Read" = "e1fe6dd8-ba31-4d61-89e7-88639da4683d"
}
$tmpReq = New-TemporaryFile
$reqObj = @{
requiredResourceAccess = @(
@{
resourceAppId = $graphAppId
resourceAccess = @(
foreach ($id in $scopes.Values) {
@{ id = $id; type = "Scope" }
}
)
}
)
}
$reqObj | ConvertTo-Json -Depth 5 | Set-Content -Path $tmpReq -Encoding UTF8
Write-Host "`nCreating SharePoint Connection App Registration..." -ForegroundColor Cyan
$appRaw = az ad app create `
--display-name $displayName `
--sign-in-audience AzureADMultipleOrgs `
--web-redirect-uris $redirectUri `
--enable-id-token-issuance false `
--enable-access-token-issuance false `
--required-resource-accesses "@$tmpReq" `
--only-show-errors
$app = $appRaw | ConvertFrom-Json
$appId = $app.appId
$appObjectId = $app.id
Write-Host "Creating Service Principal..." -ForegroundColor Cyan
$spRaw = az ad sp create --id $appId --only-show-errors
$sp = $spRaw | ConvertFrom-Json
Write-Host "Creating 2-year client secret..." -ForegroundColor Cyan
$credRaw = az ad app credential reset `
--id $appId `
--display-name "sharepoint-secret" `
--years 2 `
--only-show-errors
$cred = $credRaw | ConvertFrom-Json
$clientSecret = $cred.password
$result = [pscustomobject]@{
ApplicationName = $displayName
TenantId = $tenantId
ClientId = $appId
ClientObjectId = $appObjectId
ServicePrincipalObjectId = $sp.id
RedirectUri = $redirectUri
DelegatedPermissions = $scopes.Keys -join ", "
ImplicitGrantEnabled = $false
ClientSecret = $clientSecret
SecretExpiresOn = $cred.endDate
}
Write-Host "`n=== SharePoint Connection App Created ===" -ForegroundColor Green
$result | Format-List
$outFile = "sharepoint-connection-output.json"
$result | ConvertTo-Json -Depth 5 | Set-Content -Path $outFile -Encoding UTF8
Write-Host "`nSaved output to $outFile" -ForegroundColor Yellow
Write-Host "IMPORTANT: Store the ClientSecret securely. It cannot be retrieved later." -ForegroundColor Red
Script Summaries#
Both scripts produce a summary JSON file in the current directory containing:Service Principal Object ID
You can safely share these credentials with the Ejento team for integration.
Security Considerations#
Store client secrets securely. Once generated, the ClientSecret cannot be retrieved later.
Limit access to the JSON output files to only authorized personnel.
Ensure that proper admin consent is granted for required permissions.