Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/309.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 正在将令牌作为应用程序获取,因此委派权限不适用。您能否确切地告诉我,申请此委派权限需要做哪些更改。如果您可以在此处看到示例应用程序:。这是API的身份验证配置。您可以在这里看到它是如何使用获得令牌的:非常感谢@juunas提供的解决方案。我使用您提供的示例_C#_Angularjs_Api_Azure Active Directory_Microsoft Graph Api - Fatal编程技术网

C# 正在将令牌作为应用程序获取,因此委派权限不适用。您能否确切地告诉我,申请此委派权限需要做哪些更改。如果您可以在此处看到示例应用程序:。这是API的身份验证配置。您可以在这里看到它是如何使用获得令牌的:非常感谢@juunas提供的解决方案。我使用您提供的示例

C# 正在将令牌作为应用程序获取,因此委派权限不适用。您能否确切地告诉我,申请此委派权限需要做哪些更改。如果您可以在此处看到示例应用程序:。这是API的身份验证配置。您可以在这里看到它是如何使用获得令牌的:非常感谢@juunas提供的解决方案。我使用您提供的示例,c#,angularjs,api,azure-active-directory,microsoft-graph-api,C#,Angularjs,Api,Azure Active Directory,Microsoft Graph Api,正在将令牌作为应用程序获取,因此委派权限不适用。您能否确切地告诉我,申请此委派权限需要做哪些更改。如果您可以在此处看到示例应用程序:。这是API的身份验证配置。您可以在这里看到它是如何使用获得令牌的:非常感谢@juunas提供的解决方案。我使用您提供的示例代码创建了新函数来获取令牌。我欠你很多!! $scope.resetPassword = function () { $http({ method: 'POST', url: 'api/tenant/admin/user


正在将令牌作为应用程序获取,因此委派权限不适用。您能否确切地告诉我,申请此委派权限需要做哪些更改。如果您可以在此处看到示例应用程序:。这是API的身份验证配置。您可以在这里看到它是如何使用获得令牌的:非常感谢@juunas提供的解决方案。我使用您提供的示例代码创建了新函数来获取令牌。我欠你很多!!
    $scope.resetPassword = function () {
        $http({ method: 'POST', url: 'api/tenant/admin/user/resetpassword', data: $scope.tenantUserPostModel }).success(function (response, status) {
            if (response) {
                console.log('inside response ' + response);
                noty({ timeout: 2000, layout: 'topRight', text: 'Changes saved successfully', type: 'success' });
                document.getElementById("passwordDetails").style.display = "block";
            }
        });
    };
[HttpPost]
    [Route("api/tenant/admin/user/resetpassword")]
    public async Task<IHttpActionResult> ResetPassword([FromBody]TenantUserPostModel model)
    {
        #region update azure ad user

        string userPrincipalName = model.UserName;
        if (!model.UserName.Contains("@"))
        {
            var DefaultDomain = ConfigurationManager.AppSettings["DefaultDomain"];
            userPrincipalName = model.UserName + "@" + DefaultDomain;
        }

        //*********************************************************************************************
        // update azure ad user
        //*********************************************************************************************
        var activeDirectoryClient = GetActiveDirectoryClientAsApplication();
        IUser userToBeUpdated = new Microsoft.Azure.ActiveDirectory.GraphClient.User();
        try
        {
            List<IUser> users = activeDirectoryClient.Users
                .Where(user => user.UserPrincipalName.Equals(userPrincipalName))
                .ExecuteAsync().Result.CurrentPage.ToList();
            userToBeUpdated = users.First();
        }
        catch (Exception e)
        {
            throw e;
        }

        userToBeUpdated.DisplayName = model.DisplayName;
        userToBeUpdated.GivenName = model.FirstName;
        userToBeUpdated.Surname = model.LastName;
        userToBeUpdated.AccountEnabled = model.IsActive;
        userToBeUpdated.PasswordProfile = new PasswordProfile
        {
            Password = model.TempPassword,
            ForceChangePasswordNextLogin = true
        };

        try
        {
            //error here 'Insufficient privileges to complete the operation'
            await userToBeUpdated.UpdateAsync(false);
        }
        catch (Exception e)
        {
            throw e;
        }
        #endregion
        return this.Ok(model.Id);
    }
    protected ActiveDirectoryClient GetActiveDirectoryClientAsApplication()
    {
        Uri servicePointUri = new Uri(_GraphResourceId);
        Uri serviceRoot = new Uri(servicePointUri, _Tenant);
        var activeDirectoryClient = new ActiveDirectoryClient(serviceRoot,
             async () => await AcquireTokenAsyncForApplication());
        return activeDirectoryClient;
    }

    private string GetTokenForApplication()
    {
        if (ExtendedUserProfile == null)
            throw new Exception("initialize ExtendedUserProfile...");
        string AuthString = _AadInstance + _Tenant;
        AuthenticationContext authenticationContext = new AuthenticationContext(AuthString, false);
        ClientCredential clientCred = new ClientCredential(_ClientId, _Key);
        AuthenticationResult authenticationResult = authenticationContext.AcquireTokenAsync(_GraphResourceId,
            clientCred).Result;
        string token = authenticationResult.AccessToken;
        return token;
    }

    private async Task<string> AcquireTokenAsyncForApplication()
    {
        return GetTokenForApplication();
    }