Improve Your Technology

Just another blog for techology

Custom authentication to WCF service

Creating Custom Claims

1. Create a .NET Class library project

2. Add “System.ServiceModel” name space to the class ( using System.ServiceModel;)

3. Inherit ServiceAuthorizationManager class. E.g. below public class Class1 : ServiceAuthorizationManager

4. Override CheckAccess method

5. Write your own custom logic. You can add logic for windows account validation and client certificate validation.

6. Windows account validation a. You can get user account using “OperationContext.ServiceSecurityContext”, you can validate the user with your custom logic.

7. Client certificate validation a. You can get client certificate details using “ServiceSecurityContext.Current.AuthorizationContext”, it contains “X509CertificateClaimSet” objects. By reading certificate object you can get client certificate details.

Configuring changes to web.config

1. Open web.config of WCF service

2. Add below entry in the <behavior> section (Path: configuration\system.serviceModel\behaviors\serviceBehaviors\behavior) <serviceAuthorization serviceAuthorizationManagerType=”ClassLibrary1.Class1, ClassLibrary1″>

3. Save the web.config

Changes to Service Configuration

1. Open IIS Manager

2. Open WCF configured site

3. If you are making custom windows account authentication then enable windows authentication to your service.

4. If you are making custom client certificate based authentication then enable anonymous authentication

5. Make your service as HTTPS, and make required SSL setting to Required.

Advertisements

February 14, 2012 Posted by | ASP.NET and WCF, Custom authentication to WCF service, Technology | , | Leave a comment