Skip to content

Commit cc90f61

Browse files
shnatarashnatara
authored andcommitted
Adding a method to get the Directory Tenant Id from the Identity System
Updated eteh README file
1 parent 3397df7 commit cc90f61

2 files changed

Lines changed: 36 additions & 1 deletion

File tree

Identity/AzureStack.Identity.psm1

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,31 @@
11
# Copyright (c) Microsoft Corporation. All rights reserved.
22
# See LICENSE.txt in the project root for license information.
33

4+
<#
5+
.Synopsis
6+
Get the Guid of the directory tenant
7+
.DESCRIPTION
8+
This function fetches the OpenID configuration metadata from the identity system and parses the Directory TenantID out of it.
9+
Azure Stack AD FS is configured to be a single tenanted identity system with a TenantID.
10+
.EXAMPLE
11+
Get-DirectoryTenantIdentifier -authority https://login.windows.net/microsoft.onmicrosoft.com
12+
.EXAMPLE
13+
Get-DirectoryTenantIdentifier -authority https://adfs.local.azurestack.external/adfs
14+
#>
15+
function Get-DirectoryTenantIdentifier
16+
{
17+
[CmdletBinding()]
18+
Param
19+
(
20+
# Param1 help description
21+
[Parameter(Mandatory=$true,
22+
Position=0)]
23+
$Authority
24+
)
25+
26+
return $(Invoke-RestMethod $("{0}/.well-known/openid-configuration" -f $authority.TrimEnd('/'))).issuer.TrimEnd('/').Split('/')[-1]
27+
}
28+
429
<#
530
.Synopsis
631
This function is used to create a Service Principal on teh AD Graph

Identity/README.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,16 @@ Then make sure the following modules are imported:
1010
Import-Module ..\Connect\AzureStack.Connect.psm1
1111
Import-Module .\AzureStack.Identity.psm1
1212
```
13+
## Getting the directory tenant identifier from the Identity System
14+
15+
This function is used to get the Directory Tenant Guid. This method works for both AAD and AD FS.
16+
17+
```powershell
18+
$directoryTenantId = Get-DirectoryTenantIdentifier -Authority "<DirectoryTenantUrl>"
19+
```
20+
An example of an authority for AAD is `https://login.windows.net/microsoft.onmicrosoft.com`
21+
and for AD FS is `https://adfs.local.azurestack.global/adfs`.
22+
1323
## Creating a Service Principal in a disconnected (AD FS) topology
1424
You can create a Service Principal by executing the following command after importing the Identity Module
1525

@@ -20,5 +30,5 @@ $servicePrincipal = New-ADGraphServicePrincipal -DisplayName "<YourServicePrinci
2030
After the Service Principal is created, you should open your Azure Stack Portal to provide the appropriate level of RBAC to it. You can do this from the Access Control (IAM) tab of any resource. After the RBAC is given, you can login using the service principal as follows:
2131

2232
```powershell
23-
Add-AzureRmAccount -EnvironmentName "<AzureStackEnvironmentName>" -ServicePrincipal -CertificateThumbprint $servicePrincipal.Thumbprint -ApplicationId $servicePrincipal.ApplicationId -TenantId "<yourTenantId>"
33+
Add-AzureRmAccount -EnvironmentName "<AzureStackEnvironmentName>" -ServicePrincipal -CertificateThumbprint $servicePrincipal.Thumbprint -ApplicationId $servicePrincipal.ApplicationId -TenantId $directoryTenantId
2434
```

0 commit comments

Comments
 (0)