gpt4 book ai didi

azure - 如何在没有 user_impersonation OAuth2Permission 的情况下创建新的 Azure 应用程序注册?

转载 作者:行者123 更新时间:2023-12-02 23:49:55 25 4
gpt4 key购买 nike

我想知道 Azure 专家中是否有人可以澄清 New-AzureADApplication 的行为。当我在 PowerShell 中创建应用程序注册时,它似乎在 GUI 中的 Expose and API > Scopes Defined by this API 下添加了一个 user_impersonation。当我在 GUI 中创建应用程序注册时,我会为其提供名称并在必要时提供重定向 URI,但不会创建此 user_impersonation 范围。

我认为这可能与 AzureAD 模块有关,并且它与 Azure AD 的特定连接,但使用 New-AzADApplication 时的行为是相同的,但此 cmdlet 还需要指定 -IdentifierUris - 这对于我们注册的所有应用程序来说并不是必需的。

当我通过 PowerShell 创建应用程序注册时,是否有办法避免添加 OAuth2Permissions

我尝试过的其他事情:

  • -OAuth2Permissions 设置为类型的空列表[System.Collections.Generic.List`1[[Microsoft.Open.AzureAD.Model.OAuth2Permission, Microsoft. Open.AzureAD16.Graph.Client,版本=0.1.599.7,文化=中性,PublicKeyToken=null]]

  • 使用Get-AzureADOAuth2PermissionGrant尝试找到该权限并在之后将其删除。它不在那里。

如果我在创建时无法避免或删除它,那么请提供以下信息:

  • 为什么默认需要此权限。
  • 为什么 GUI 认为没有必要。

示例:

Connect-AzureAD
$GraphRead = Get-AzureADServicePrincipal -All $true | Where-Object {$_.AppId -eq '00000003-0000-0000-c000-000000000000'}
$RRA = New-Object -TypeName "Microsoft.Open.AzureAD.Model.RequiredResourceAccess"
$RRA.ResourceAppId = $GraphRead.AppId
$ResAcc = New-Object -TypeName "microsoft.open.azuread.model.resourceAccess" -ArgumentList "e1fe6dd8-ba31-4d61-89e7-88639da4683d", "Scope"
$RRA.ResourceAccess = $ResAcc
$Test = New-AzureADApplication -DisplayName "PoshTest" -ReplyUrls "https://visualstudio/spn" -RequiredResourceAccess @($RRA)

对象:

$Test | FL *

DeletionTimestamp :
ObjectId : ************************************
ObjectType : Application
AddIns : {}
AppId : ************************************
AppRoles : {}
AvailableToOtherTenants : False
DisplayName : PoshTest
ErrorUrl :
GroupMembershipClaims :
Homepage :
IdentifierUris : {}
KeyCredentials : {}
KnownClientApplications : {}
LogoutUrl :
Oauth2AllowImplicitFlow : False
Oauth2AllowUrlPathMatching : False
Oauth2Permissions : {class OAuth2Permission {
AdminConsentDescription: Allow the application to access PoshTest on behalf of the
signed-in user.
AdminConsentDisplayName: Access PoshTest
Id: ************************************
IsEnabled: True
Type: User
UserConsentDescription: Allow the application to access PoshTest on your behalf.
UserConsentDisplayName: Access PoshTest
Value: user_impersonation
}
}
Oauth2RequirePostResponse : False
PasswordCredentials : {}
PublicClient :
RecordConsentConditions :
ReplyUrls : {https://visualstudio/spn}
RequiredResourceAccess : {class RequiredResourceAccess {
ResourceAppId: 00000003-0000-0000-c000-000000000000
ResourceAccess:
System.Collections.Generic.List`1[Microsoft.Open.AzureAD.Model.ResourceAccess]
}
}
SamlMetadataUrl :

PowerShell 详细信息

$PSVersionTable | select PSVersion,PSEdition,OS,Platform | FL *

PSVersion : 7.0.2
PSEdition : Core
OS : Darwin 18.7.0 Darwin Kernel Version 18.7.0: Mon Apr 27 20:09:39 PDT 2020;
root:xnu-4903.278.35~1/RELEASE_X86_64
Platform : Unix

Get-Module -Name AzureAD.Standard.Preview

ModuleType Version PreRelease Name
---------- ------- ---------- ----
Script 0.1.599.7 AzureAD.Standard.Preview

GUI 的差异

GUITest PoshTest

最佳答案

我已经设法解决了这个问题,因此想为可能也试图从其应用程序注册中删除此权限的其他人留下适当的答案分割。

正如我在上面探索的那样,我走在正确的道路上,有一个空的[Microsoft.Open.AzureAD.Model.OAuth2Permission]列表。

如果您通过 New-AzureADApplication 应用此功能创建您的应用程序时,它绝对不会产生任何影响。

如果您直接通过Set-AzureADApplication应用此创建新的应用程序注册后,您将收到如下错误:

Set-AzureADApplication: Error occurred while executing SetApplication 
Code: Request_BadRequest
Message: Property value cannot be deleted or updated unless it is disabled first.
RequestId: ********-****-****-*****************
DateTimeStamp: Thu, 02 Jul 2020 10:11:54 GMT
Details: PropertyName - None, PropertyErrorCode - CannotDeleteEnabledEntitlement
HttpStatusCode: BadRequest
HttpStatusDescription: Bad Request
HttpResponseStatus: Completed

因此,解决方案是首先创建一个新列表,将旧范围添加到其中,同时将值 IsEnabled 设置为 $false

# New Azure AD Application
Connect-AzureAD
$GraphRead = Get-AzureADServicePrincipal -All $true | Where-Object {$_.AppId -eq '00000003-0000-0000-c000-000000000000'}
$RRA = New-Object -TypeName "Microsoft.Open.AzureAD.Model.RequiredResourceAccess"
$RRA.ResourceAppId = $GraphRead.AppId
$ResAcc = New-Object -TypeName "microsoft.open.azuread.model.resourceAccess" -ArgumentList "e1fe6dd8-ba31-4d61-89e7-88639da4683d", "Scope"
$RRA.ResourceAccess = $ResAcc
$Test = New-AzureADApplication -DisplayName "PoshTest" -ReplyUrls "https://visualstudio/spn" -RequiredResourceAccess @($RRA)

# Disable the App Registration scope.
$Scopes = New-Object System.Collections.Generic.List[Microsoft.Open.AzureAD.Model.OAuth2Permission]
$Scope = $Test.Oauth2Permissions | Where-Object { $_.Value -eq "user_impersonation" }
$Scope.IsEnabled = $false
$Scopes.Add($Scope)
Set-AzureADApplication -ObjectId $Test.ObjectID -Oauth2Permissions $Scopes

您最终可以通过应用空列表来完全删除 OAuth2Permssion

$EmptyScopes = New-Object System.Collections.Generic.List[Microsoft.Open.AzureAD.Model.OAuth2Permission]
Set-AzureADApplication -ObjectId $Test.ObjectID -Oauth2Permissions $EmptyScopes

使用Get-AzureADApplication获取该对象的最新信息,您应该看到 OAuth2Permissions 列表现在为空。

$Test = Get-AzureADApplication -ObjectId $Test.ObjectID
$Test | FL *

DeletionTimestamp :
ObjectId : ********-****-****-*****************
ObjectType : Application
AddIns : {}
AppId : ********-****-****-*****************
AppRoles : {}
AvailableToOtherTenants : False
DisplayName : PoshTest
ErrorUrl :
GroupMembershipClaims :
Homepage :
IdentifierUris : {}
KeyCredentials : {}
KnownClientApplications : {}
LogoutUrl :
Oauth2AllowImplicitFlow : False
Oauth2AllowUrlPathMatching : False
Oauth2Permissions : {}
Oauth2RequirePostResponse : False
PasswordCredentials : {}
PublicClient :
RecordConsentConditions :
ReplyUrls : {https://visualstudio/spn}
RequiredResourceAccess : {class RequiredResourceAccess {
ResourceAppId: 00000003-0000-0000-c000-000000000000
ResourceAccess:
System.Collections.Generic.List`1[Microsoft.Open.AzureAD.Model.ResourceAccess]
}
}
SamlMetadataUrl :

关于azure - 如何在没有 user_impersonation OAuth2Permission 的情况下创建新的 Azure 应用程序注册?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62691947/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com