我正嘗試在ASP.Net MVC中創建一個頁面來重置當前用戶的密碼。我正在使用Azure活動目錄進行用戶驗證。要訪問用戶的AD信息,我正在使用C#Graph API客戶端。我的代碼基於在GitHub使用Azure AD Graph客戶端API更改用戶密碼的權限問題
上找到的樣本。我可以對用戶的信息(如城市,州,郵件)進行更改。但是,當我嘗試使用用戶對象上的PasswordProfile屬性更改密碼時,出現錯誤,表示我的權限不足。我正在嘗試將密碼更改爲應用程序,並且我認爲權限問題的來源與應用程序有關。
我找到了下面的PowerShell腳本,它應該將公司管理員角色添加到應用程序中。但是,對Get-MsolServicePrincipal的調用不會返回任何內容。查看命令的輸出,我沒有看到任何類似於我的應用程序名稱的條目。
#-----------------------------------------------------------
# This will prompt you for your tenant's credential
# You should be able to use your your Azure AD administrative user name
# (in the [email protected] format)
#-----------------------------------------------------------
import-module MSOnline
Connect-MsolService
#-----------------------------------------------------------
# Replace the Application Name with the name of your
# Application Service Principal
#-----------------------------------------------------------
$displayName = "My Azure AD Application"
$objectId = (Get-MsolServicePrincipal -SearchString $displayName).ObjectId
#-----------------------------------------------------------
# This will add your Application Service Prinicpal to
# the Company Administrator role
#-----------------------------------------------------------
$roleName = "Company Administrator"
Add-MsolRoleMember -RoleName $roleName -RoleMemberType ServicePrincipal -RoleMemberObjectId $objectId
我想我的第一個問題是我正確的權限問題是與應用程序?
其次,我應該設置$ displayName變量的值是多少?
您可以擴展如何創建UserCredential?我所看到的唯一屬性和構造函數是用戶名。桌面應用程序和Web應用程序庫有區別嗎? –
我不認爲存在差異否,下面是使用'UserCredential'的一些信息... http://www.cloudidentity.com/blog/2014/07/08/using-adal-net-to-authenticate -users-via-usernamepassword /基本用法雖然是...'var credential = new UserCredential(「username」,「password」);' –
由於某種原因,UserCredential對我來說沒有兩個構造函數,但UserPasswordCredential可以做到這一點。在調整我的常量和權限之後,我讓它工作。謝謝。 –