Banner Image
Jürgen Bäurle
Projects  ·  Work  ·  Blog  ·  Contact

Using A Custom Authentication Provider For The SharePoint 2010 BCS Administration Object Model

November 15, 2010

Authentication, Business Connectivity Services, ECT, SharePoint

The SharePoint 2010 Business Connectivity Services (BCS) are providing an Administration Object Model to manage all kind of BCS objects. You can use the an Administration Object Model to programmatically create BDC models, LOB system and instances, Entities and Methods. The Microsoft SharePoint Designer is using the object model itself to let you generate External Content Types (ECT).

The sample code is this blog entry is a WPF client application which will read all BDC model names and display them in a ListView control. The application allows the user to enter credentials other than the current Windows user:

The starting point to access the BCS data is the AdministrationMetadataCatalog class. This class is part of the Microsoft.SharePoint.BusinessData.Administration.Client.dll library and namespace. You also need a reference to the Microsoft.BusinessData.dll library.

In order to create an instance of the AdministrationMetadataCatalog class with custom credentials we have to call the GetCatalog method. We need to pass a custom authentication provider as parameter to GetCatalog. A custom authentication provider is a class which implements the ILobiAuthenticationProvider interface. The interface is quite simple, it just asks you to return the user ID (including the domain name) and the according password.

Here the code of your custom authentication provider:

internal class SharePointConnection : ILobiAuthenticationProvider
    // . . .

    public SharePointConnection(string userId, string password)
        UserId = userId;
        Password = password;

    public AuthenticationScheme GetAuthenticationScheme(string server, string serverUrl)
        return AuthenticationScheme.RunAs;

    public string GetCookie(string server, string serverUrl)
        return "BCSCustomAuthenticationProvider";

    public string GetUserId(string server, string serverUrl)
        return UserId;

    public string GetPassword(string server, string serverUrl)
        return Password;

Here the sample on how to use the provider:

// Create instance of custom authentication provider
SharePointConnection spc = new SharePointConnection(UserIdText.Text, PasswordText.Text); 

// Create catalog instance using the custom authentication provider
AdministrationMetadataCatalog catalog = AdministrationMetadataCatalog.GetCatalog(SiteURLText.Text, spc);

ModelsListView.ItemsSource = catalog.GetModels("*").Select(m => m.Name);

Important: If you create your own WPF application using the BCS Administration Object Model and reference the Microsoft.SharePoint.BusinessData.Administration.Client.dll library, you need to set the Platform Target to “Any CPU” in the application settings page, otherwise the project will not compile.

Download Source Code