ume*_*mer 2 oauth-2.0 azure-devops azure-devops-rest-api
I have implemented an OAuth2 app for Azure DevOps. My website takes user (User A) to authorize the app using the below URL. Step1
https://app.vssps.visualstudio.com/oauth2/authorize?scope=vso.code_full (skipped the other parameters)
Run Code Online (Sandbox Code Playgroud)
The above URL works fine and returns with a code+userInfo after user authorization. Now I get an access token passing the code returned from the app using the below API call.
https://app.vssps.visualstudio.com/oauth2/token
Run Code Online (Sandbox Code Playgroud)
I can further fetch all the organizations associated with user's (User A ) account using the below API call
Step2
https://app.vssps.visualstudio.com/_apis/accounts?api-version=6.0-preview&memberId=xyz
Run Code Online (Sandbox Code Playgroud)
Now I want to fetch the repositories inside a particular organization. For that I make the below API call.
Step3
https://dev.azure.com/**organization_name**/_apis/git/repositories?api-version=5.0
Run Code Online (Sandbox Code Playgroud)
The above URL works fine and returns to the repositories inside the specified organization.
Everything fine so far.
现在,另一个用户(用户 B)正在尝试连接我的应用程序,他可以授权该应用程序,并且我的应用程序可以获取该经过身份验证的用户帐户下的组织。例如,直到步骤2 为止一切都很好。但它在第 3 步失败,例如它无法获取用户(用户 B)组织内的存储库。步骤 3 中的 API 调用返回并出现以下错误
TF400813: 用户无权访问此资源。
请帮忙。
为了进一步澄清,我怀疑问题出在经过身份验证的用户 (user B ) 上,因为整个过程对于一个经过身份验证的用户 (用户 A ) 来说工作正常,但对于其他用户 (用户 B ) 来说则失败。所以第二个经过身份验证的用户一定有一些不同。但我不确定这是什么,因为我不是 Azure 人员。
另请注意,当我使用用户 A 或用户 B 登录时,我可以查看我的组织/项目/存储库,也可以添加/删除组织/项目/存储库。(我是组织所有者)
那么,如果我能够使用登录用户查看我的组织/存储库,并且同一用户正在验证 OAuth 应用程序,那么为什么用户生成的访问令牌无权访问用户 B 帐户中的存储库?
我在这里找到了缺失的部分。
我必须转到组织的设置,如下面的 URL
https://dev.azure.com/my_organization_name/_settings/organizationPolicy
Run Code Online (Sandbox Code Playgroud)
并选中应用程序连接策略下的第一个复选框,即通过 OAuth 的第三方应用程序访问
通过选中此选项,我也可以获取用户 B 帐户下的存储库。
遗憾的是微软没有这方面的文档。讨厌微软产品的另一个原因。
归档时间: |
|
查看次数: |
2158 次 |
最近记录: |