All Projects → itemir → apache_2fa

itemir / apache_2fa

Licence: BSD-2-Clause license
Apache two-factor (2FA) authentication with Google Authenticator based on Time-based One-Time Password (TOTP) or HMAC-based one-time password (HOTP) Algorithms.

Programming Languages

python
139335 projects - #7 most used programming language
HTML
75241 projects
shell
77523 projects

Projects that are alternatives of or similar to apache 2fa

2FAuth
A Web app to manage your Two-Factor Authentication (2FA) accounts and generate their security codes
Stars: ✭ 664 (+953.97%)
Mutual labels:  two-factor, totp, hotp, two-factor-authentication, 2fa
cotp
Trustworthy, encrypted, command-line TOTP/HOTP authenticator app with import functionality.
Stars: ✭ 45 (-28.57%)
Mutual labels:  totp, hotp, google-authenticator, authy
Twofactor totp
🔑 Second factor TOTP (RFC 6238) provider for Nextcloud
Stars: ✭ 203 (+222.22%)
Mutual labels:  two-factor, totp, two-factor-authentication, 2fa
Speakeasy
**NOT MAINTAINED** Two-factor authentication for Node.js. One-time passcode generator (HOTP/TOTP) with support for Google Authenticator.
Stars: ✭ 2,531 (+3917.46%)
Mutual labels:  two-factor, totp, hotp, two-factor-authentication
Authenticatorpro
📱 Two-Factor Authentication (2FA) client for Android + Wear OS
Stars: ✭ 155 (+146.03%)
Mutual labels:  totp, hotp, two-factor-authentication, 2fa
totp
Time-Based One-Time Password Code Generator
Stars: ✭ 76 (+20.63%)
Mutual labels:  two-factor, totp, two-factor-authentication, 2fa
Onetimepassword
🔑 A small library for generating TOTP and HOTP one-time passwords on iOS.
Stars: ✭ 243 (+285.71%)
Mutual labels:  totp, hotp, two-factor-authentication, 2fa
Authelia
The Single Sign-On Multi-Factor portal for web apps
Stars: ✭ 11,094 (+17509.52%)
Mutual labels:  two-factor, totp, two-factor-authentication, 2fa
Otplib
🔑 One Time Password (OTP) / 2FA for Node.js and Browser - Supports HOTP, TOTP and Google Authenticator
Stars: ✭ 916 (+1353.97%)
Mutual labels:  two-factor, hotp, two-factor-authentication, 2fa
One Time
One Time Password (TOTP and HOTP) library for Clojure. TOTP/HOTP is widely used for Two Factor / Multi Factor Authentication.
Stars: ✭ 129 (+104.76%)
Mutual labels:  totp, hotp, two-factor-authentication, 2fa
Otpauth
One Time Password (HOTP/TOTP) library for Node.js, Deno and browsers.
Stars: ✭ 135 (+114.29%)
Mutual labels:  two-factor, totp, hotp, two-factor-authentication
SimpleTOTP
A highly configurable yet simple to use TOTP based two-factor authentication processing module for SimpleSAMLphp.
Stars: ✭ 16 (-74.6%)
Mutual labels:  totp, google-authenticator, two-factor-authentication, 2fa
rx-otp
HMAC-based (HOTP) and Time-based (TOTP) One-Time Password manager. Works with Google Authenticator for Two-Factor Authentication.
Stars: ✭ 79 (+25.4%)
Mutual labels:  totp, hotp, google-authenticator, two-factor-authentication
Java Otp
A one-time password (HOTP/TOTP) library for Java
Stars: ✭ 265 (+320.63%)
Mutual labels:  totp, hotp, two-factor-authentication, 2fa
crotp
CrOTP - One Time Passwords for Crystal
Stars: ✭ 62 (-1.59%)
Mutual labels:  totp, hotp, two-factor-authentication, 2fa
otp-java
A small and easy-to-use one-time password generator library for Java according to RFC 4226 (HOTP) and RFC 6238 (TOTP).
Stars: ✭ 107 (+69.84%)
Mutual labels:  totp, hotp, two-factor-authentication, 2fa
Go Guardian
Go-Guardian is a golang library that provides a simple, clean, and idiomatic way to create powerful modern API and web authentication.
Stars: ✭ 204 (+223.81%)
Mutual labels:  totp, hotp, 2fa
Freeotpplus
Enhanced fork of FreeOTP-Android providing a feature-rich 2FA authenticator
Stars: ✭ 223 (+253.97%)
Mutual labels:  totp, hotp, 2fa
Aegis
A free, secure and open source app for Android to manage your 2-step verification tokens.
Stars: ✭ 2,692 (+4173.02%)
Mutual labels:  totp, hotp, 2fa
2FA-Auth
Generating 2FA codes in your terminal
Stars: ✭ 23 (-63.49%)
Mutual labels:  two-factor, two-factor-authentication, 2fa

Apache Two-Factor (2FA) Authentication with Google Authenticator

Two-factor authentication also known as 2FA, adds an extra step to a basic authentication procedure. Without 2FA, a user only enters username and password. In this case, the password is the single factor of authentication. With 2FA an additional authentication mechanism is used, that is preferably performed out-of-band.

Google Authenticator is an application that implements two-factor authentication services using the Time-based One-time Password Algorithm (TOTP).

Apache provides basic authentication mechanism with mod_auth_basic or mod_auth_digest. For more secure applications, it is often required to have an additional layer of authentication. This repository provides necessary code and instructions to add two-factor authentication to basic Apache authentication. This method is transparent to underlying applications so it can be used for any Apache served web site whether it is static, dynamic (PHP, Django, Flask etc.) or pre-packaged (Wiki, CRM, CMS etc.).

Specific instructions are provided below for configuring two-factor authentication with mod_auth_digest, but the same code and approach can be used with different Apache authentication mechanisms with slight modifications. Similarly, it is also possible to use the same code with slight modifications and the same approach to provide 2FA based on HMAC-based one-time password (HOTP) algorithm.

Instructions

Clone the repository and install dependencies:

$ git clone https://github.com/itemir/apache_2fa
$ cd apache_2fa
$ sudo pip install onetimepass

Create a directory for storing states:

$ mkdir state

Adjust permissions to allow access only to Apache (replace www-data with the user id of Apache process as needed):

$ sudo chown www-data:www-data state
$ sudo chown www-data:www-data tokens.json
$ sudo chmod 750 state
$ sudo chmod 640 tokens.json

Enable mod_rewrite, mod_auth_digest and mod_cgid if not already enabled (you will need to restart Apache):

$ sudo a2enmod rewrite
$ sudo a2enmod auth_digest
$ sudo a2enmod cgid
$ sudo service apache2 restart

Add the following configuration to Apache configuration under appropriate VirtualHost:

RewriteEngine On

RewriteCond %{REQUEST_URI} !^/auth/
RewriteCond %{HTTP_COOKIE} !^.*2FA_Auth=([a-zA-Z0-9]+)
RewriteRule ^(.*)$ /auth/auth?$1?%{QUERY_STRING} [L,R=302]

RewriteCond %{REQUEST_URI} !^/auth/
RewriteCond %{HTTP_COOKIE} ^.*2FA_Auth=([a-zA-Z0-9]+)
RewriteCond <path to apache_2fa>/state/%1 !-f
RewriteRule ^(.*)$ /auth/auth?$1?%{QUERY_STRING} [L,R=302]

ScriptAlias /auth/ <path to_apache 2fa (note the trailing slash)>/

<Directory <path to apache_2fa>>
    AuthType Digest
    AuthName "yourdomain.com"
    AuthDigestDomain /
    AuthDigestProvider file
    AuthUserFile <path to apache_2fa>/apache_credentials
    Require valid-user
</Directory>

<Directory <path to protected directory>>
    AuthType Digest
    AuthName "yourdomain.com"
    AuthDigestDomain /
    AuthDigestProvider file
    AuthUserFile <path to apache_2fa>/apache_credentials
    Require valid-user
</Directory>

Replace path to apache_2fa with the full path of cloned repository, path to protected directory with the actual path of the site you are trying to protect. If you change yourdomain.com make sure to make corresponding changes in apache_credentials file. Pay special attention to trailing slashes where present. You may be able to combine two Directory configurations into one depending on your directory structure, just make sure both paths are covered by the same auhentication mechanism.

NOTE: This configuration is for https. For a setup like this, using http is not recommended. However, if you want to test it with http you need to make changes to the auth script and comment out the following two lines:

cookie['2FA_Auth']['secure'] = True
cookie['2FA_Auth']['httponly'] = True

Test the configuration and reload Apache if no errors. If there are errors, verify steps above and make sure if you have all necessary modules enabled.

$ sudo apachectl configtest
$ sudo service apache2 reload

If all went well, you can now test the application. Go to a protected web page. You should be prompted to enter a username and password. Use test_user / test_password. You should now be prompted for an Authentication Token. If test_user authentication fails, change the password with the following command:

$ htdigest apache_credentials yourdomain.com test_user

In order to obtain Authentication Token, download Google Authenticator for iOS or Android and create a profile by using ND4LKCSFMUQISO6CBZQATLDP secret key (there are many other applications that provide the same capability with additional features, you can basically use any application that supports TOTP). Once you define a profile, Google Authenticator will create a token that you can use in this form.

If the test is successful, edit apache_credentials and tokens.json files and remove test_user.

Maintenance

You can create new users by using htdigest tool:

$ htdigest apache_credentials yourdomain.com <new_user>

For creating secret keys for Google Authenticator, refer to this article. You need to save generated secret keys (base32) in tokens.json file.

For every successful authentication session, a new file will be created under /state directory. This file is relevant until the cookie expires (default value is 6 hours for expiration). You will eventually want to clean stale entried in this directory. state_clean utility that is included the repository can be used to delete state files that are older than 6 hours. You can call it from a cron job every hour which also prevents users from manually increasing the expiration timer of cookies to delay token re-authorization:

0 * * * * <path to apache_2fa>/state_clean
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].