TfsAuthentication Class

Represents a client-side authentication mechanism for Team Foundation Server (TFS) that is based on HTTP basic authentication.

Namespace: System.Net.Security Assembly: System.Net.dll

Syntax

public sealed class TfsAuthentication : Object, IAuthenticationModule

Remarks

The TfsAuthentication class is used by the .NET Framework to authenticate clients to a Team Foundation Server instance. It implements the IAuthenticationModule interface, which allows it to be registered with the HttpWebRequest.AuthenticationTypes property.

When a HttpWebRequest attempts to connect to a TFS server that requires authentication, the TfsAuthentication module will intercept the request and provide the necessary credentials.

Constructors

TfsAuthentication()

Initializes a new instance of the TfsAuthentication class.

Methods

Name Description
Authenticate(string challenge, HttpWebRequest request, ICredentials credentials) Returns an IAuthenticationHeader object that can be used to authenticate the specified HttpWebRequest.
PreAuthenticate(HttpWebRequest request, ICredentials credentials) Returns true if the authentication module can pre-authenticate the specified HttpWebRequest; otherwise, false.

Properties

Name Description
AuthenticationType Gets the type of authentication supported by this module.

Examples

The following example demonstrates how to register the TfsAuthentication module and use it to authenticate with a TFS server.

using System;
using System.Net;
using System.Net.Security;

public class Example
{
    public static void Main(string[] args)
    {
        // Register the TfsAuthentication module
        AuthenticationManager.Register(new TfsAuthentication(), "TFS");

        // Create a new HttpWebRequest
        HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://your-tfs-server/tfs/DefaultCollection");

        // Set the credentials for the request
        request.Credentials = new NetworkCredential("username", "password");

        // Get the response
        try
        {
            using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
            {
                Console.WriteLine("Authentication successful!");
            }
        }
        catch (WebException ex)
        {
            Console.WriteLine($"Authentication failed: {ex.Message}");
        }
    }
}

Requirements

Feature Requirement
Namespace System.Net.Security
Assembly System.Net.dll
.NET Framework versions Available in: 4.5, 4.0, 3.5, 3.0
Last modified: January 20, 2023 © Microsoft Corporation. All rights reserved.