从 Connect-AzureAd 公开连接令牌
Exposing the Connection token from Connect-AzureAd
我正在使用 AzureAd Powershell module 进行用户管理。但是它没有我需要的所有功能,具体来说,我不能为对象分配应用程序扩展值,(尽管我可以通过 [Get/New/Remove]-AzureADApplicationExtensionProperty
自己创建删除和删除应用程序扩展)。
我通过 Fiddler 观察 API 调用知道图调用使用不记名令牌,我直接从 Postman 手动调用图 API 所以我知道如果我能得到它,如何使用 Bearer 令牌。我如何获得它?
要获取令牌,只需使用:
$token = [Microsoft.Open.Azure.AD.CommonLibrary.AzureSession]::AccessTokens['AccessToken']
可是怎么会得出这个结论呢?
首先查找模块所在位置:
(Get-Module AzureAd).Path
C:\Program Files\WindowsPowerShell\Modules\AzureAD.0.1.3\Microsoft.Open.AzureAD16.Graph.PowerShell.dll
现在让我们做两个假设。首先,令牌存储在静态 class 的静态成员中,其次,它可能不存储在该 dll 中,而是存储在文件夹中的任何 DLL 中。
$fileInfo = New-Object 'IO.FileInfo' (Get-Module AzureAd).Path
$moduleFolder = $fileInfo.Directory.FullName
$assemblies = [AppDomain]::CurrentDomain.GetAssemblies() | where { $_.Location -ne $null -and $_.Location.StartsWith($moduleFolder)}
$assemblies | select -expandproperty ExportedTypes | Where { $_.IsSealed -and $_.IsAbstract } | Select Name, FullName
顺便说一句,最后一行是因为奇怪的方式 static types are noted in IL。
输出一个非常小的列表:
Name FullName
---- --------
RestSharpExtensionMethods Microsoft.Open.Azure.AD.CommonLibrary.RestSharpExtensionMethods
AzureSession Microsoft.Open.Azure.AD.CommonLibrary.AzureSession
DictionaryExtensions Microsoft.Open.Azure.AD.CommonLibrary.DictionaryExtensions
Logger Microsoft.Open.Azure.AD.CommonLibrary.Logger
ImageUtils Microsoft.Open.Azure.AD.CommonLibrary.Utilities.ImageUtils
SecureStringExtension Microsoft.Open.Azure.AD.CommonLibrary.Extensions.SecureStringExtension
AzureEnvironmentConstants Microsoft.Open.Azure.AD.CommonLibrary.AzureEnvironment+AzureEnvironmentConstants
TypeToOdataTypeMapping Microsoft.Open.AzureAD16.Client.TypeToOdataTypeMapping
JsonConvert Newtonsoft.Json.JsonConvert
Extensions Newtonsoft.Json.Linq.Extensions
Extensions Newtonsoft.Json.Schema.Extensions
TypeToOdataTypeMapping Microsoft.Open.MSGraphV10.Client.TypeToOdataTypeMapping
AdalError Microsoft.IdentityModel.Clients.ActiveDirectory.AdalError
AuthenticationContextIntegratedAuthExtensions Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContextIntegratedAuthExtensions
AdalOption Microsoft.IdentityModel.Clients.ActiveDirectory.AdalOption
MiscExtensions RestSharp.Extensions.MiscExtensions
ReflectionExtensions RestSharp.Extensions.ReflectionExtensions
ResponseExtensions RestSharp.Extensions.ResponseExtensions
ResponseStatusExtensions RestSharp.Extensions.ResponseStatusExtensions
StringExtensions RestSharp.Extensions.StringExtensions
XmlExtensions RestSharp.Extensions.XmlExtensions
RestClientExtensions RestSharp.RestClientExtensions
SimpleJson RestSharp.SimpleJson
如果列表较长,我们可以通过 Out-Gridview,但我的注意力立即被吸引到了 AzureSession
。在那之后有一点 PowerShell 自动完成,我找到了通往 [Microsoft.Open.Azure.AD.CommonLibrary.AzureSession]::AccessTokens['AccessToken']
的路
我正在使用 AzureAd Powershell module 进行用户管理。但是它没有我需要的所有功能,具体来说,我不能为对象分配应用程序扩展值,(尽管我可以通过 [Get/New/Remove]-AzureADApplicationExtensionProperty
自己创建删除和删除应用程序扩展)。
我通过 Fiddler 观察 API 调用知道图调用使用不记名令牌,我直接从 Postman 手动调用图 API 所以我知道如果我能得到它,如何使用 Bearer 令牌。我如何获得它?
要获取令牌,只需使用:
$token = [Microsoft.Open.Azure.AD.CommonLibrary.AzureSession]::AccessTokens['AccessToken']
可是怎么会得出这个结论呢?
首先查找模块所在位置:
(Get-Module AzureAd).Path
C:\Program Files\WindowsPowerShell\Modules\AzureAD.0.1.3\Microsoft.Open.AzureAD16.Graph.PowerShell.dll
现在让我们做两个假设。首先,令牌存储在静态 class 的静态成员中,其次,它可能不存储在该 dll 中,而是存储在文件夹中的任何 DLL 中。
$fileInfo = New-Object 'IO.FileInfo' (Get-Module AzureAd).Path
$moduleFolder = $fileInfo.Directory.FullName
$assemblies = [AppDomain]::CurrentDomain.GetAssemblies() | where { $_.Location -ne $null -and $_.Location.StartsWith($moduleFolder)}
$assemblies | select -expandproperty ExportedTypes | Where { $_.IsSealed -and $_.IsAbstract } | Select Name, FullName
顺便说一句,最后一行是因为奇怪的方式 static types are noted in IL。
输出一个非常小的列表:
Name FullName
---- --------
RestSharpExtensionMethods Microsoft.Open.Azure.AD.CommonLibrary.RestSharpExtensionMethods
AzureSession Microsoft.Open.Azure.AD.CommonLibrary.AzureSession
DictionaryExtensions Microsoft.Open.Azure.AD.CommonLibrary.DictionaryExtensions
Logger Microsoft.Open.Azure.AD.CommonLibrary.Logger
ImageUtils Microsoft.Open.Azure.AD.CommonLibrary.Utilities.ImageUtils
SecureStringExtension Microsoft.Open.Azure.AD.CommonLibrary.Extensions.SecureStringExtension
AzureEnvironmentConstants Microsoft.Open.Azure.AD.CommonLibrary.AzureEnvironment+AzureEnvironmentConstants
TypeToOdataTypeMapping Microsoft.Open.AzureAD16.Client.TypeToOdataTypeMapping
JsonConvert Newtonsoft.Json.JsonConvert
Extensions Newtonsoft.Json.Linq.Extensions
Extensions Newtonsoft.Json.Schema.Extensions
TypeToOdataTypeMapping Microsoft.Open.MSGraphV10.Client.TypeToOdataTypeMapping
AdalError Microsoft.IdentityModel.Clients.ActiveDirectory.AdalError
AuthenticationContextIntegratedAuthExtensions Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContextIntegratedAuthExtensions
AdalOption Microsoft.IdentityModel.Clients.ActiveDirectory.AdalOption
MiscExtensions RestSharp.Extensions.MiscExtensions
ReflectionExtensions RestSharp.Extensions.ReflectionExtensions
ResponseExtensions RestSharp.Extensions.ResponseExtensions
ResponseStatusExtensions RestSharp.Extensions.ResponseStatusExtensions
StringExtensions RestSharp.Extensions.StringExtensions
XmlExtensions RestSharp.Extensions.XmlExtensions
RestClientExtensions RestSharp.RestClientExtensions
SimpleJson RestSharp.SimpleJson
如果列表较长,我们可以通过 Out-Gridview,但我的注意力立即被吸引到了 AzureSession
。在那之后有一点 PowerShell 自动完成,我找到了通往 [Microsoft.Open.Azure.AD.CommonLibrary.AzureSession]::AccessTokens['AccessToken']