VSTS身份验证中具有访问令牌凭证的VssClientCredentials [英] VssClientCredentials with accesstoken credentials in VSTS authentication
本文介绍了VSTS身份验证中具有访问令牌凭证的VssClientCredentials的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在从VSTS中读取用户的许可信息,但未使用访问令牌凭据对其进行身份验证.
I am reading licensing information of user from VSTS but it is not authenticating itself with Access Token credentials.
string accessToken = "{AccessTokenHere}";
VssOAuthAccessTokenCredential accessTokenCredentials = new VssOAuthAccessTokenCredential(new VssOAuthAccessToken(accessToken));
var credentials = new VssClientCredentials(accessTokenCredentials);
VssConnection connection = new VssConnection(new Uri(this.ServerUri), credentials);
var licensingHttpClient = connection.GetClient<LicensingHttpClient>();
var accountEntitlement = licensingHttpClient.GetAccountEntitlementAsync().Result;
var license = accountEntitlement.License;
推荐答案
我认为,当您拥有来自oauth2身份验证的承载令牌时,可以跳过以下行:
I think, you can skip the following line, when you have the bearer token from an oauth2 authentication:
// skip this line in your code: var credentials = new VssClientCredentials(accessTokenCredentials);
对我来说,此代码有效:
For me, this code is working:
VssOAuthAccessTokenCredential credentials = new VssOAuthAccessTokenCredential(AccessToken);
VssConnection connection = new VssConnection(new Uri("https://dev.azure.com/[your org]"), credentials);
var client = connection.GetClient<ProjectHttpClient>();
var projects = client.GetProjects().Result;
还请确保您为想要达到的目标在应用程序中注册了正确的作用域.
Please also make sure, you register the correct scopes in your application for whatever you are trying to achieve.
这篇关于VSTS身份验证中具有访问令牌凭证的VssClientCredentials的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文