The finest control over authentication is given by set one or more custom authentication provider. A custom authentication provider is a .Net Framework class which implement this IAuthenticator interface:

using DotNetNuke.Entities.Users;
using DotNetNuke.Security.Membership;
namespace Iconsulting.MDM.MDMWebServices.Components.Authentication.ForeingAuthentication {
 public interface IAuthenticator {
 int Priority { get; }
 UserInfo FreshLogin(int portalId, string username, string password, ref UserLoginStatus loginStatus);

Of course you can place every authentication logic you want in this class, and interact with your specific authentication API.

Once you have implemented this interface, follow these steps:

- compile it in a class library (dll)

- rename it with .plugin extension (so for example if your class library is called CustomAuthenticator.dll the output file name should be CustomAuthenticator.dll.plugin)

- place it the root/bin folder of your FORMWORK instance 

- restart the instance if it was running

You have finished your work.

When the FORMWORK instance boots it scans root/bin folder searching .plugin files and loads them respecting theirs individual Priority.