Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

Cross Domain/Platform Authentication and Data Transfer

, 29 Dec 2008 CPOL
Introduces a methodology for authenticating user in cross domain/platform and transferring user data from one site to another during the authentication process.
CrossSiteAuthentication.zip
CrossSiteAuthentication
AuthenticationSite
App_Code
App_Data
CustomerDB.mdf
CustomerDB_Log.LDF
Bin
Microsoft.Practices.EnterpriseLibrary.Common.dll
Microsoft.Practices.EnterpriseLibrary.Data.dll
Microsoft.Practices.EnterpriseLibrary.Data.dll.refresh
Microsoft.Practices.ObjectBuilder.dll
images
line.JPG
Site1.JPG
Site2.JPG
ThirdPartySite
App_Code
App_WebReferences
AuthenticationService
AuthenticationService.disco
AuthenticationService.discomap
AuthenticationService.wsdl
images
line.JPG
Site1.JPG
Site2.JPG
using System;
using System.Data;
using System.Web;
using System.Collections;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.ComponentModel;
using System.Collections.Specialized;
using System.Configuration;


/// <summary>
/// Summary description for AuthenticationService
/// </summary>
[WebService(Namespace = "http://www.CrossSiteAuthentication.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class AuthenticationService : System.Web.Services.WebService
{
    public AuthenticationService()
    {

        //Uncomment the following line if using designed components 
        //InitializeComponent(); 
    }

    //this method confirms authentication status and returns UserID if successful, empty string if not
    [WebMethod(Description = "Upon success, returns UserID as a string. "
        + "Upon failure, returns an empty string and sends back error messages in the ref parameter returnMessage."
        + "If you do not need a complete set of user data but only confirm that the user is authenticated, this is the method to call.")]
    public string RetrieveUserID(ref string returnMessage, string authenticationID)
    {
        string UserID = "";
        NameValueCollection UserDataCollection = GetUserDataCollection(ref returnMessage, authenticationID);
        if (returnMessage=="")
            UserID = UserDataCollection["CustomerID"].ToString();

        return UserID;
    }
    private NameValueCollection GetUserDataCollection(ref string returnMessage, string authenticationID)
    {
        NameValueCollection UserDataCollection = null;
        try
        {
            //Get data collection based on authenticationID
            DataTable tbl = Authentication.ExecuteDataSet("AuthenticationLog_get", new object[] { authenticationID }).Tables[0];
            if (tbl.Rows.Count == 0)
                throw new Exception("Url parameter might be altered or url has expired.");

            UserDataCollection = Authentication.DeserializeUserData(tbl.Rows[0]["UserData"].ToString());
        }
        catch (Exception ex)
        {
            returnMessage = ex.Message.ToString();
        }
        return UserDataCollection;
    }


    [WebMethod(Description = "Upon success, returns complete user data as a seriailized xml string. "
       + "Upon failure, returns an empty string and sends back error messages in the ref parameter returnMessage.")]
    public string RetrieveUserDataXml(ref string returnMessage, int siteID, string authenticationID)
    {
        //siteID determine what storedproc to use for retrieving user data from database
        string UserXML = "";
        DataSet ds = RetrieveUserDataSet(ref returnMessage, authenticationID);
        if (ds != null)
        { UserXML = ds.GetXml(); }
        return UserXML;
    }

    [WebMethod(Description = "Upon success, returns complete user data as a DataSet. "
        + "Upon failure, returns null and sends back error messages in the ref parameter returnMessage.")]
    public DataSet RetrieveUserDataSet(ref string returnMessage, string authenticationID)
    {
        NameValueCollection UserDataCollection = new NameValueCollection();
        UserDataCollection=GetUserDataCollection(ref returnMessage, authenticationID);
        if (returnMessage == "")
            return RetrieveUserDataSetByID(ref returnMessage,
                int.Parse(UserDataCollection["SiteID"]),
                UserDataCollection["CustomerID"]);
        else
            return null;
    }

    [WebMethod(Description = "Pass in a known clear text UserID to retrieve complete user data as a DataSet. "
        + "Upon failure, returns null and sends back error messages in the ref parameter returnMessage.")]
    private DataSet RetrieveUserDataSetByID(ref string returnMessage, int siteID, string clearUserID)
    {
        DataSet ds = null;
        try
        {
            ds = Authentication.RetrieveUserDataSet(siteID, clearUserID);
            //check empty DataSet
            bool EmptyDataSet = true;
            for (int i = 0; i < ds.Tables.Count; i++)
            {
                if (ds.Tables[i].Rows.Count > 0)
                {
                    EmptyDataSet = false;
                    break;
                }
            }
            if (EmptyDataSet)
            {
                ds = null;
                returnMessage +="No data returned for the authenticated user.";
            }
        }
        catch (Exception ex)
        {
            returnMessage += ex.Message.ToString();
        }
        return ds;
    }

}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Tomz_KV
Web Developer
United States United States
Web & Database Developer. Design and implement web and database applications utilizing Microsoft and other development tools.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.1411023.1 | Last Updated 29 Dec 2008
Article Copyright 2008 by Tomz_KV
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid