


|
|
UThe FuseTalk External Authentication Module
Platform: .NET
What Is the External Authentication Module?
Preparing to use the External Authentication Module
The External Authentication Wizard
Cookie Authentication (Wizard)
External Authentication Scripting
The Code Explained
This guide is meant as a supplement to the documentation provided in the global administration area. Please read the external authentication documentation along with this article. You can find a copy of the documentation here.
WHAT IS THE EXTERNAL AUTHENTICATION MODULE?
|
The External Authentication Module (EAM) is a very flexible feature of FuseTalk which lets you integrate a login system, which your website currently uses. This means that if a user has already performed a login procedure on your website, once they hit FuseTalk, the user will not have to login a second time.
The EAM is very flexible and can be integrated with any authentication system which you are currently using. The EAM is divided in two different modules. If you are using Cookies or Sessions on your website to keep the user state, you can use the external authentication wizard. If you are using any other method to keep state on your website you can use the open concept login templates which are described in detailed below.
|
PREPARING TO USE THE EXTERNAL AUTHENTICATION MODULE
|
Since the EAM uses credentials that have been entered on your web site, FuseTalk requires you to pass a few details in order for the authentication to happen. The required details are, username, e-mail address, first name, and last name. Each section will describe how to pass this information to FuseTalk.
|
THE EXTERNAL AUTHENTICATION WIZARD
|
The external authentication wizard is a very innovative feature which lets you setup your authentication in a few minutes. The wizard only works with stand-alone forums. For global forums proceed to "EXTERNAL AUTHENTICATION SCRIPTING". Follow the steps below to start the wizard:
| 1. | Login to the Global Administrator. |
| 2. | Enter the "Forums - Management" section. |
| 3. | Update the forum you wish to use the wizard with by selecting the update icon, the update forum window will open. |
| 4. | Select the "authentication" tab. |
| 5. | Select "Yes" for the External Authentication setting and click the "Update Settings" button. |
| 6. | Select "Yes" for the User Authentication Wizard setting and click the "Update Settings" button. |
| 7. | A javascript alert box will appear telling you that the current users who are attached to the forum will no longer be able to login through FuseTalk. This is because the login button will disappear. Click on OK. |
| 8. | Select the "Open Authentication Wizard" Link. |
|
COOKIE AUTHENTICATION (WIZARD)
|
The following are step by step details on how to setup cookie authentication with the wizard.
| 1. | Select the "next" button of the first welcome screen of the wizard. |
| 2. | On the second screen (selecting the authentication method) select "Cookies" and select the next button. |
NOTE: FuseTalk assumes that the cookie which will be read by FuseTalk contains a "key" to data which is available in a database. For example, your cookie might contain a user ID which references a record in the table of your database. FuseTalk also assumes that you can get the required details (username, first and last name and e-mail address from the query). This is an example of a query.
Select username, email, firstname, lastname from employees
where employeeid = #employeeid#
|
| 3. | Enter the Query information to retrieve the required details, in the text box provided. |
| 4. | Enter the "Datasource" name which points to the database that you are accessing in the query. |
| 5. | If your datasource requires you to login, enter the username and password in "DB Username" and "DB Password". |
| 6. | Enter the username, e-mail address, firstname and lastname field information. |
In our case this is how step 3 of the wizard would look like:
| 7. | Select the "Next" button, to proceed. |
| 8. | The fourth screen off the wizard lets you decide if your users require to login before accessing FuseTalk. If they do require to login select the "Yes" radio button, and enter the URL of the login template on your website. (The login template will be the location where the user is redirected if a user attempts to access FuseTalk without being logged in.) If you wish for users to be able to browser the forums without being logged in, select the "No" radio button. |
| 9. | Select the "Next" button, to proceed. |
| 10. | The fifth screen is a review of your information. Ensure that the information entered is correct, if so select the "Finish" button. |
You have completed the authentication wizard and you are now ready to try it out. To do so login on your web site, then enter FuseTalk. You should be logged in.
|
EXTERNAL AUTHENTICATION SCRIPTING
|
If, for various reasons, you cannot use the External Authentication Wizard you can script your own authentication using login templates which can be edited. It is very useful to understand all the steps that make this feature work.
| 1. | A user enters FuseTalk from your web site. |
| 2. | FuseTalk detects that the Authentication Module has been enabled for the specified forum and includes the authentication module in the process. |
| 3. | FuseTalk uses the custom scripts that you have created to authenticate the user. |
| 4. | Using variables that your custom scripts will set, FuseTalk detects if the user is validated. If the user has been validated, FuseTalk performs the necessary steps to log in the user. Also, since FuseTalk is a highly customizable system, you need a record for the user in your FuseTalk database. During this step FuseTalk checks the FuseTalk database to see if a record already exists for the user: if not, a new record is created. |
| 5. | The Authentication Feature sends the user information back to FuseTalk, which can then perform normal operations as though the user was always logged in. |
Now that you understand how this feature interacts with FuseTalk, you are ready to open the authentication template and create your own authentication scripts. In our example we will be using Cookies to login the users, and the user will be required to login before browsing the forums. Follow these steps to create your external authentication scripts.
| 1. | Login to the Global Administrator. |
| 2. | Enter the "Forums - Management" section. |
| 3. | Update the forum you wish to use the wizard with by selecting the update icon, the update forum window will open. |
| 4. | Select the "authentication" tab. |
| 5. | Select "Yes" for the External Authentication setting and click the "Update Settings" button. |
| 6. | Ensure that "No" is selected for the User Authentication Wizard setting and click the "Update Settings" button. |
| 7. | Open the login.ascx template located in the forum/modules/authentication directory if you are using this for a STAND-ALONE forum. Open the loginglobal.ascx template located in the forum/modules/authentication directory if you are using this for a GLOBAL forum. Your authentication scripts should go between these comments: |
<!--- INSERT CODE HERE --->
YOUR SCRIPT GOES HERE
<!--- END CODE HERE --->
|
|
| 8. | Insert the following script between the comments. |
<%@Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Control Language="vb" AutoEventWireup="false" Inherits="ExternalAuth"
TargetSchema="http://schemas.microsoft.com/intellisense/ie5" %>
<script language="vb" runat="server">
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs)_
Handles MyBase.Init
'Check if the cookie exists
If Request.Cookies("mysitecookie") Is Nothing Then
'If cookie does not exists
're-direct to your login template.
Response.Redirect("http://www.mywebsite.com/login.aspx")
End If
'If the cookie exists
'Prepare Variables needed to run a query to get the required user information
Dim Con As System.Data.SqlClient.SqlConnection
Dim cmd As System.Data.SqlClient.SqlCommand
Dim ds As System.Data.DataSet
Dim sqlData As System.Data.SqlClient.SqlDataAdapter
'Define the Query
Dim Query As String = "select username, emailaddress, firstname, lastname from myusers
where userid = " & Request.Cookies("mysitecookie").Value
'Open a connection (Replace YOUR CONNECTION STRING HERE with a valid connection
string to your user database.
'i.e. server=127.0.0.1;database=myusers;uid=myuser;pwd=mypassword;
Con = New System.Data.SqlClient.SqlConnection("YOUR CONNECTION STRING HERE")
Con.Open()
'Execute the query and fill the dataset
cmd = New System.Data.SqlClient.SqlCommand(Query, Con)
ds = New System.Data.DataSet
sqlData = New System.Data.SqlClient.SqlDataAdapter(cmd)
sqlData.Fill(ds, "qCheckUser")
'If no records are found, redirect the user to your login template
If ds.Tables(0).Rows.Count = 0 Then
Response.Redirect("http://www.mywebsite.com/login.aspx")
End If
'Populate the FuseTalk Variables with the information which you gathered from the
database.
UserName = ds.Tables(0).Rows(0).Item("username")
EmailAddress = ds.Tables(0).Rows(0).Item("emailaddress")
FirstName = ds.Tables(0).Rows(0).Item("firstname")
LastName = ds.Tables(0).Rows(0).Item("lastname")
End Sub
</script>
|
| 9. | Save your template. Because FuseTalk is a multi-forum system you will need to save the template you created with the filename that has the following format: login<forumid>.ascx. Replace the <forumid> with the ID of the forum. The forum ID can be retrieved by entering the global administration area and searching for the forum under "FORUMS - Management". The ID can be found in the first column. If you are using a global forum, you do not need to do this since you should have edited the loginglobal.ascx template. |
You have completed the authentication script and you are now ready to try it out. To do so login on your web site, then enter FuseTalk. You should be logged in.
Now that you know how to create the scripts let us explain what the script means.
|
THE CODE EXPLAINED
|
This command states that if the cookie named mysitecookie does not exists,
redirect the user to http://www.mywebsite.com/login.aspx.
In our case this is the location the user would need to login on to our web site in order to
access FuseTalk.
'Check if the cookie exists
If Request.Cookies("mysitecookie") Is Nothing Then
'If cookie does not exists
're-direct to your login template.
Response.Redirect("http://www.mywebsite.com/login.aspx")
End If
This command retrieves the required details from a database.
'Prepare Variables needed to run a query to get the required user information
Dim Con As System.Data.SqlClient.SqlConnection
Dim cmd As System.Data.SqlClient.SqlCommand
Dim ds As System.Data.DataSet
Dim sqlData As System.Data.SqlClient.SqlDataAdapter
'Define the Query
Dim Query As String = "select username, emailaddress, firstname, lastname from
myusers
where userid = " & Request.Cookies("mysitecookie").Value
'Open a connection (Replace YOUR CONNECTION STRING HERE with a valid connection
string to your user database.
'i.e. server=127.0.0.1;database=myusers;uid=myuser;pwd=mypassword;
Con = New System.Data.SqlClient.SqlConnection("YOUR CONNECTION STRING HERE")
Con.Open()
'Execute the query and fill the dataset
cmd = New System.Data.SqlClient.SqlCommand(Query, Con)
ds = New System.Data.DataSet
sqlData = New System.Data.SqlClient.SqlDataAdapter(cmd)
sqlData.Fill(ds, "qCheckUser")
This command states that if the query does not return any rows (because the user doesn't exist, or the cookie does not have a correct value) re-direct the user to the login template on your web site.
'If no records are found, redirect the user to your login template
If ds.Tables(0).Rows.Count = 0 Then
Response.Redirect("http://www.mywebsite.com/login.aspx")
End If
These commands set the firstname, lastname, username and email address of the user.
UserName = ds.Tables(0).Rows(0).Item("username")
EmailAddress = ds.Tables(0).Rows(0).Item("emailaddress")
FirstName = ds.Tables(0).Rows(0).Item("firstname")
LastName = ds.Tables(0).Rows(0).Item("lastname")
Below is a representation of these steps with an explanation. There are six variables which will require your attention during the scripting process. These are them with a description:
| UserName: |
This variable is used by FuseTalk and should contain the user's username. |
| EmailAddress: |
This variable is used by FuseTalk and should contain the user's e-mail address. |
| FirstName: |
This variable is used by FuseTalk and should contain the user's last name. If you do not have leave blank. |
| LastName: |
This variable is used by FuseTalk and should contain the user's first name. If you do not have leave blank. |
|
Hopefully this article has given you a better understanding on how the external authentication system of FuseTalk works. If you have any other questions about external authentication please do not hesitate to contact support@fusetalk.com. Also there are numerous example in the documentation an in the samples directory of your FuseTalk install that will help guide you through the process.
To discuss this article or to ask question please visit our forums.
|