Sivarajan's Blog

SharePoint | Office 365 | Azure | JavaScript

SharePoint 2013 Custom Claims (FBA) based Mixed Mode Authentication - Part 1

SharePoint 2013 Custom Claims (FBA) based Mixed Mode Authentication - Part 1

Learn on how to  enable custom form based authentication for SharePoint Server 2013. Like that you can find the walkthrough for implementing custom login page here.

Solution

I found the few samples from CodePlex for mixed mode and FBA based authentication and could not find the complete solutions for custom FBA. I am going to provide a step by step walk-though using SQL server.

  • Step 1: Create a web application with mixed mode authentication
  • Step 2: Change the web.config settings
  • Step 3: Membership table structure
  • Step 4: Override the Membership provider
  • Step 5: Testing the mixed mode authentication

Step 1: Create a web application with mixed mode authentication

Create a new web application with the following parameters.

claims1

After successful creation, create the site collection for implement the mixed mode authentication.

Step 2: Change the web.config settings

For enable the custom form based authentication, we have to change the two web.config files

  1. Newly created web application
  2. Security Token Service

To change the web application web.config file, open the folder C:\inetpub\wwwroot \wss\VirtualDirectories\50001

Search the web.config with the text <PeoplePickerWildcards> and add the following entries like below

<PeoplePickerWildcards>

<clear />

<add key="AspNetSqlMembershipProvider" value="%" />

<add key="CustomFBA_Membership" value="%" />

</PeoplePickerWildcards>

Search the web.config with the text <membership and add the following entries like below

<membership defaultProvider="i">

<providers>

<add name=" CustomFBA_Membership" type="CustomFBA.CustomDbMembershipProvider, CustomFBA, Version=1.0.0.0, Culture=neutral, PublicKeyToken=ed357cb2eca26bd5" />

</providers>

</membership>

Note: The attribute PublicKeyToken will be varied for each visual studio solutions and you can find the details in my blog on how to get this token in Visual Studio 2012.

To change the Security Token service web.config file, open the folder C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\WebServices\SecurityToken

Search the web.config with the text <membership and add the following entries like below

<membership defaultProvider="i">

<providers>

<add name=" CustomFBA_Membership" type="CustomFBA.CustomDbMembershipProvider, CustomFBA, Version=1.0.0.0, Culture=neutral, PublicKeyToken=ed357cb2eca26bd5" />

</providers>

</membership>

 

Step 3: Membership table structure

Create the table “Users” with the following columns.

claims2

Step 4: Override the Membership provider

Here we will create an empty SharePoint Project “CustomFBA” and add the following references

1. System.Web.Extensions

2. System.Web.ApplicationServices

3. Microsoft.IdentityModel

4. System.Configuration

Add a new class file “CustomDbMembershipProvider.cs” and override with Membership class. I have created a new class “MemberShipProviderData” for database operations and have used SQLHelper classes for database operation. Same you can extend this helper class for other databases like MySQL, Oracle and SAP. This is my solution and custom membership class structure.

claims3

 

claims4

Step 5: Test the mixed mode authentication

In the users table, I added the few users for testing.

claims5

For demo, I have added a plain password in the users table and same you can use different encrypt mechanism for password field.

Now browse the newly created site collection and choose the “Windows Authentication” option.

claims6

After the login, grand the permissions for form authentication users and see the sample below.

claims7

Summary

In the next post, we will see more walk-though for User Registration, Custom Login, Password recovery and Manage users. You can find the code sample here.

Comments (13) -

  • andy

    5/18/2013 5:41:07 AM | Reply

    hi, Sivarajan

    I followed your article step by step. But after deployment, when I browse the site, it prompt the following error:
    Could not load type 'CustomFBA.CustomDbMemberhipProvider' from assembly 'CustomFBA, Version=1.0.0.0, Culture=neutral, PublicKeyToken=de4e65a8432e97bf'.


    Line 619:      <providers>
    Line 620:        <add name="i" type="Microsoft.SharePoint.Administration.Claims.SPClaimsAuthMembershipProvider, Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" />
    Line 621:        <add name="CustomFBA_Membership" type="CustomFBA.CustomDbMemberhipProvider, CustomFBA, Version=1.0.0.0, Culture=neutral, PublicKeyToken=de4e65a8432e97bf" />
    Line 622:      </providers>
    Line 623:    </membership>

    Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.17929

    Could you give me some instrument?

    thanks~~

    • Sivarajan Raju

      5/18/2013 7:30:16 AM | Reply

      Hi,

      Please use this, there is a spelling mistake in type.

      <add name="CustomFBA_Membership" type="CustomFBA.CustomDbMembershipProvider, CustomFBA, Version=1.0.0.0, Culture=neutral, PublicKeyToken=de4e65a8432e97bf" />

      Regards,
      Siva

  • andy

    5/19/2013 12:50:25 AM | Reply

    My carelessness, Many thanks for your help.

  • Sourav

    8/8/2013 4:51:43 AM | Reply

    Hi Siva,

    Awesome explanation for FBA custom login. However got stuck in Step 3 and 4. Want more detail on how to create Sharepoint Project in VS2010. Can you please help.
    Also I am creating FBA in sharepoint foundation 2013 with VS2010. is it fine?

    Sourav

    • Sivarajan

      8/8/2013 7:09:37 PM | Reply

      Hi,

      After creating a table structure and web.cofig changes, better you download the attached source code and try to deploy.

      Note: This is developed using VS 2012 and it is recommended one for Sharepoint 2013.

      Kindly ping me if you have any questions?

      Regards,
      Siva

  • Sourav

    8/9/2013 3:07:44 AM | Reply

    Ok thanks for your help. my i have your personal email id to quick refer you if I have any doubt doing this task.

    Sourav

  • Aravindh

    9/9/2013 12:55:51 PM | Reply

    Hi Siva,

    I already have a table with usernames and SHA-1 hashed passwords. Can I use this table instead?

    Regards,
    Aravindh

    • Sivarajan Raju

      10/14/2013 2:16:14 AM | Reply

      Yes, you can use your own table

  • Aravindh

    10/15/2013 8:57:28 AM | Reply

    Hi Raju,

    Thanks for your response. I am facing this error when I try to login to my new site collection after altering the web application's web.config.

    Parser Error Message: Could not load file or assembly 'CustomFBA, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c' or one of its dependencies. The system cannot find the file specified.

    Source Error:



    Line 633:      <providers>
    Line 634:        <add name="i" type="Microsoft.SharePoint.Administration.Claims.SPClaimsAuthMembershipProvider, Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" />
    Line 635:  <add name="CustomFBA_Membership" type="CustomFBA.CustomDbMembershipProvider, CustomFBA, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"/>
    Line 636:      </providers>
    Line 637:    </membership>

  • Aravindh

    10/18/2013 12:18:24 PM | Reply

    Hello Once again..

    The Could not load file or assembly error got resolved once I updated the correct public key token. But now.. Once I deploy this wsp and try to add my users as Site Collection Administrators, it says No Users Found. I am not able to see these users in the people picker either. Can you tell me where I might be going wrong.

    Regards,
    Aravindh

  • Amit

    4/10/2014 9:54:46 PM | Reply

    Hello Sir,

    Very nice demo, Can you help me to get this code.
    From where i can Download above code.
    becase i can see only CustomDBMemberShipProvider class code, but what about other classes.

    Thanks in Advance..

    • Sivarajan Raju

      4/15/2014 8:44:44 AM | Reply

      Hi Amit,

      Here I have customized only CustomDBMemberShipProvider class.

  • Amit

    4/11/2014 2:57:43 AM | Reply

    Can you please share your Code

Pingbacks and trackbacks (2)+

Add comment

Loading