获取OAuth令牌以使用Azure DevOps API [英] Getting OAuth tokens for Azure DevOps API consumption
问题描述
我有一个用Angular 7编写的Web应用程序.我正在尝试使用Azure DevOps API,并且我了解我必须设置一个Azure Active Directory App.我尝试过一些库,例如adal-angular
msal-angular
和包装器(例如microsoft-adal-angular6
).遵循他们的文档和样本.我可以成功访问用户名,电子邮件和令牌.我可以将令牌用于Microsoft Graph API,但不能用于Azure DevOps API.我尝试将此令牌用作HttpClient
的身份验证Bearer
,但是我收到状态码203.
然后我找到了这个 answer ,我认为这是我需要的缺失部分,但对于dotNet来说是必需的.
该API直接包含: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'])
getCachedTokenInternal([499b84ac-1321-427f-aa17-267ca6975798/.default])
检索访问令牌
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.
Then I found this answer and I think this is the missing part that I need but its for dotNet.
The API Im cosuming: https://app.vssps.visualstudio.com/_apis/accounts
Q:
- What is the token Im getting?
- How can I get the appropriate token using Angular 7?
- What libraries do I need?
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'])
access token can be retrieved via getCachedTokenInternal([499b84ac-1321-427f-aa17-267ca6975798/.default])
这篇关于获取OAuth令牌以使用Azure DevOps API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!