Skip to content

Basic Authentication Handler Overview

orand edited this page May 23, 2012 · 3 revisions

WCF REST Contrib ships with the basic authentication handler WcfRestContrib.ServiceModel.Dispatcher.WebBasicAuthenticationHandler. This handler allows you to enable basic authentication on a per service or operation basis. It is implemented independent of IIS so does not require any special web server configuration. The Basic Authentication Handler depends on the WCF REST Contrib WebErrorHandler described under WebErrorHandler Overview. To authenticate using basic authentication follow the steps outlined here but use the WcfRestContrib.ServiceModel.Dispatcher.WebBasicAuthenticationHandler as follows:

Declaratively:

[WebAuthenticationConfiguration(
    typeof(WcfRestContrib.ServiceModel.Dispatcher.WebBasicAuthenticationHandler),
    typeof(MyApplication.SecurityValidator),
    "My Application")]
public class Books : IBooksService {...}

Or in configuration as a service behavior:

<system.serviceModel>
    <extensions>
        <behaviorExtensions>
            <add name="webAuthentication" 
                 type="WcfRestContrib.ServiceModel.Configuration.WebAuthentication.ConfigurationBehaviorElement, WcfRestContrib, 
                       Version=x.x.x.x, Culture=neutral, PublicKeyToken=89183999a8dc93b5"/>
        </behaviorExtensions>
    </extensions>
    <serviceBehaviors>
        <behavior name="Rest">
            <webAuthentication 
                authenticationHandlerType="WcfRestContrib.ServiceModel.Dispatcher.WebBasicAuthenticationHandler, WcfRestContrib" 
                usernamePasswordValidatorType="MyApplication.SecurityValidator, MyApplication" 
                source="My Application"/>            
        </behavior>
    </serviceBehaviors>
</system.serviceModel>

NOTE: The WcfRestContrib.ServiceModel.Web.WebServiceHost allows you to specify configuration based behaviors if you do not want to specify this declaratively. See more about it under Declarative Binding & Behavior Overview.

Clone this wiki locally