从Connect-AzureAd公开连接令牌

时间:2018-03-30 06:43:47

标签: powershell azure-ad-graph-api

我正在使用AzureAd Powershell module进行用户管理。但是它没有我需要的所有功能,具体来说,我不能将Application Extension值分配给对象,(虽然我可以通过[Get/New/Remove]-AzureADApplicationExtensionProperty创建删除和删除应用程序扩展)。

我知道通过Fiddler观看API调用,图表调用正在使用承载令牌,我手动直接从Postman调用图API,所以我知道如果我能得到如何使用Bearer令牌它。我怎么得到它?

1 个答案:

答案 0 :(得分:1)

要获取令牌,只需使用:

  

$ token = [Microsoft.Open.Azure.AD.CommonLibrary.AzureSession] :: AccessTokens ['AccessToken']

但是怎么能得出这个结论呢?

首先查看模块所在的位置:

(Get-Module AzureAd).Path
C:\Program Files\WindowsPowerShell\Modules\AzureAD\2.0.1.3\Microsoft.Open.AzureAD16.Graph.PowerShell.dll

现在让我们做两个假设。首先,令牌存储在静态类的静态成员中,其次是它可能不存储在该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

最后一行btw是因为奇怪的方式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']

的路