さて、お勧めできませんが、可能です。社内のIT部門がHTTPS(悲しい話)でTFSをインストールしないため、私はそれも必要でした。また、シナリオをテストするためには非常に便利です。
いつものように、YMMVと私はあなたがそれを使わないと何が起こるかについて責任を負いません;-)警告されました。
http://<WHATEVER>:<BASE64PAT>@<instance>/_apis/...
(したがってこと:あなたは、単に.NETクライアントAPIを使用していないが、直接HttpClient
を使用して手動でREST APIにアクセスするためのURLでPATを入れ、例えば可能性が1の場合
tfx-cli
は、PATと非HTTPS TFSインスタンスでうまく機能します。これは内部的には.NETクライアントAPIを使用しないためです(つまり、node.jsというものです)。
.NETクライアントAPIを使用すると、次のような独自の認証情報クラスを作成できます。
using System;
using System.Linq;
using System.Net;
using Microsoft.VisualStudio.Services.Common;
namespace Utilities
{
/// <summary>
/// Same as VssBasicCredential, but doesn't throw when URL is a non SSL, i.e. http, URL.
/// </summary>
/// <inheritdoc cref="FederatedCredential"/>
internal sealed class PatCredentials : FederatedCredential
{
public PatCredentials()
: this((VssBasicToken)null)
{
}
public PatCredentials(string userName, string password)
: this(new VssBasicToken(new NetworkCredential(userName, password)))
{
}
public PatCredentials(ICredentials initialToken)
: this(new VssBasicToken(initialToken))
{
}
public PatCredentials(VssBasicToken initialToken)
: base(initialToken)
{
}
public override VssCredentialsType CredentialType => VssCredentialsType.Basic;
public override bool IsAuthenticationChallenge(IHttpResponse webResponse)
{
if (webResponse == null ||
webResponse.StatusCode != HttpStatusCode.Found &&
webResponse.StatusCode != HttpStatusCode.Found &&
webResponse.StatusCode != HttpStatusCode.Unauthorized)
{
return false;
}
return webResponse.Headers.GetValues("WWW-Authenticate").Any(x => x.StartsWith("Basic", StringComparison.OrdinalIgnoreCase));
}
protected override IssuedTokenProvider OnCreateTokenProvider(Uri serverUrl, IHttpResponse response)
{
return new BasicAuthTokenProvider(this, serverUrl);
}
private sealed class BasicAuthTokenProvider : IssuedTokenProvider
{
public BasicAuthTokenProvider(IssuedTokenCredential credential, Uri serverUrl)
: base(credential, serverUrl, serverUrl)
{
}
protected override string AuthenticationScheme => "Basic";
public override bool GetTokenIsInteractive => this.CurrentToken == null;
}
}
}
そして、このクラスを使用してVssCredentialsを作成します。
var credentials = new PatCredentials("", personalAccessToken);
var connection = new VssConnection(serverUrl, credentials);
(恥知らずなプラグインは、私は私のTfsInfoServiceでそれを使用)。
PATの代わりにWindows認証を使用できますか?クレデンシャルがクリアテキストで送信されるため、安全性を確保する基本認証は本当に悪い考えです。 –
これは私たちのtfsビルドプロセスの終わりです。一時的なトークンですが、なぜ彼らは非セキュアなものを許可したくないのか理解しています。 – dan