获取用于 Azure DevOps API 使用的 OAuth 令牌 [英] Getting OAuth tokens for Azure DevOps API consumption
问题描述
我有一个用 Angular 7 编写的 Web 应用程序.我正在尝试使用 Azure DevOps API,我知道我必须设置一个 Azure Active Directory 应用程序.我尝试过一些库,如 adal-angular
msal-angular
和包装器,如 microsoft-adal-angular6
.遵循他们的文档和示例.我可以成功访问用户的姓名、电子邮件和令牌.我可以将令牌用于 Microsoft Graph api,但不能用于 Azure DevOps api.我尝试使用此令牌作为我的 HttpClient
的身份验证 Bearer
但是我收到状态代码 203.
I have a web app written in Angular 7. I'm trying to consume Azure DevOps APIs and I understand that I have to setup an Azure Active Directory App. I have tried few libraries like adal-angular
msal-angular
and wrappers like microsoft-adal-angular6
. Followed their documentations and samples. I can successfully access the User's name, emails and a token. I can use the token for Microsoft Graph apis but not for Azure DevOps apis. I tried using this token as a Authentication Bearer
for my HttpClient
however I'm getting Status Code 203.
然后我发现了这个答案,我认为这是我需要的缺失部分,但它用于 dotNet.
Then I found this answer and I think this is the missing part that I need but its for dotNet.
我正在使用的 API:https://app.vssps.visualstudio.com/_apis/accounts
The API Im cosuming: https://app.vssps.visualstudio.com/_apis/accounts
问:
- 我得到的令牌是什么?
- 如何使用 Angular 7 获取适当的令牌?
- 我需要哪些库?
推荐答案
我使用了 @azure/msal-angular
.我使用 acquireTokenSilent(['499b84ac-1321-427f-aa17-267ca6975798/.default'])
获得了 azure dev ops 令牌.如果失败,我使用了 acquireTokenRedirect(['499b84ac-1321-427f-aa17-267ca6975798/.default'])
I used @azure/msal-angular
. I got the azure dev ops token using acquireTokenSilent(['499b84ac-1321-427f-aa17-267ca6975798/.default'])
. If it fails, I used the acquireTokenRedirect(['499b84ac-1321-427f-aa17-267ca6975798/.default'])
可以通过getCachedTokenInternal([499b84ac-1321-427f-aa17-267ca6975798/.default])
这篇关于获取用于 Azure DevOps API 使用的 OAuth 令牌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!