DreamFactory supports all kinds of authentication schemes out of the box, including traditional native authentication (managing users and passwords in its own database), OAuth 1.0 and OAuth 2.0, as well as OpenID Connect and SAML 2.0. While these options cover most authentication scenarios, there are situations where none of these solutions work. For these cases, DreamFactory 2.11 includes an alternate user authentication feature that allows you to use your own database and user table for DreamFactory user authentication.
Using the alternate authentication feature involves setting up your user database as a DreamFactory database service, configuring the built-in ‘User’ service with your database service for users, and specifying the table and fields involved in your authentication process. We'll go over the configuration and usage details below.
Note: Alternate authentication is only applicable to non-admin DreamFactory users. DreamFactory admin users are different and always use DreamFactory's native authentication.
Before you start configuring your DreamFactory instance for alternate authentication, you'll need to enable a configuration setting in your .env file. Open the .env file sitting in your DreamFactory installation root and for the following option:
## By default DreamFactory uses its own database table to authenticate all users.
## You can change that by setting the alternate auth flag below to 'true'.
## This will then allow you to configure the DreamFactory 'user' service with
## another DB service and table/fields information required for your
## custom/alternate authentication.
#DF_ENABLE_ALTERNATE_AUTH=false
Uncomment the line #DF_ENABLE_ALTERNATE_AUTH=false and set this option to true. It should look like this after your changes.
## By default DreamFactory uses its own database table to authenticate all users.
## You can change that by setting the alternate auth flag below to 'true'.
## This will then allow you to configure the DreamFactory 'user' service with
## another DB service and table/fields information required for your
## custom/alternate authentication.
DF_ENABLE_ALTERNATE_AUTH=true
After you enable the feature, log into your DreamFactory instance as an admin, head over to the ‘Services’ tab and select the ‘user’ service. Select the ‘Config’ tab of the user service. You should see some additional configuration fields with the “Alt. Auth.” prefix. We will go over configuring all these fields below.
NOTE: All field names are case sensitive. Make sure field names you specify here exactly match your actual field names.
{
"username":"jdoe",
"password”:"secret",
"country":"U.S.A"
}
Using the alternate authentication configuration you just set up is easy. You don’t have to do anything special to use it. You're going to use the same API endpoint that you would normally use to authenticate into DreamFactory (learn more here). Internally, DreamFactory will use your alternate auth configuration to perform the authentication using your own database and user table. Note that for alternate auth you will use the key name 'username' in your payload, not 'email', as in the example above.
Behind the scenes during authentication, DreamFactory makes a database service call to your user database service using a filter based on your configured fields and passed in values. If your user is found then this database service call returns the user with the password hash. It then verifies user password by checking the supplied password with the password hash retrieved from the user database service.
This blog post described how to easily set up altenate authentication in DreamFactory. Check out the community forum to discuss this feature or let us know what you think in the comments!