Business Requirement

  • OneDrive创建了一个用户级文件夹,并与团队的特定成员共享 .

  • 拥有用户为项目创建文件夹并为某些成员分配独占权限(删除对非项目成员的访问权限)

Technical Environment

  • 通过Graph API访问One Drive

  • ADAL Auth

  • Web作业在Azure App中作为NativeJob托管,并授予所需的OneDrive访问权限 .

  • 在我的应用程序中注册的应用程序(不是用于访问OneDrive的帐户)

Current Effort 由于web-api和web应用程序无法使用用户名/密码auth,访问特定用户的驱动器,使用WebJob(不确定它是否符合本机应用程序) . WebJob尝试使用驱动器所有者的凭据进行身份验证,但失败并显示消息 (AADSTS65001: The user or administrator has not consented to use the application with ID '<appId>' named 'OneDriveFileSystem'. Send an interactive authorization request for this user and resource.)

Code

验证请求

UserCredential uc = new UserPasswordCredential(userName, password);
        AuthenticationResult result = null;
        try
        {
            var authContext = new AuthenticationContext(authority);
            result = authContext.AcquireTokenAsync(resource, clientId, uc).Result;
        }
        catch (Exception ee)
        {
            return string.Empty;
        }

        return result.AccessToken;

OneDriveAccess

string accessToken = GetAuthToken();
        if (!string.IsNullOrEmpty(accessToken))
        {
            HttpClient httpClient = new HttpClient();
            httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
           string payload = "{ \"name\": \"" + projectRequest.ProjectName + "\" , \"folder\": { } }";
            HttpContent content = new StringContent(payload,
                System.Text.Encoding.UTF8,
                "application/json");  
            Uri uri = new Uri(resource + "/v1.0" + RootFolderItemId + RootFolderItemId + "/children");
            HttpResponseMessage response = httpClient.PostAsync(uri, content).Result;

            if (response.IsSuccessStatusCode)
            {
                var responseContent = response.Content;
            }
        }

(结果为404,但是相同的网址在Graph Explorer中有效)

Question

这个设计是正确的还是我错过了一些关键元素?我是否需要在用于OneDrive访问的帐户中注册应用程序,或者只要密钥正确,是否可以在任何用户的帐户中注册?

如果我更新代码以使用我的凭证,它会要求多因素身份验证(由管理员启用),但由于这是本机的,因此无法提供 . 驱动器所有者帐户是作为服务帐户创建的,因此MFA不适用于该帐户 .

可以提供所需的任何其他代码/配置

Update 1 使用基于"me"的 endpoints (默认为self的文件夹)会导致403 Forbidden,即使我正在发送有效的访问令牌 . 已授予文件访问权限(参见附图)
permissions granted
. 授予权限对所有要求的权限都是成功的 .