Skip to content

Commit 031e483

Browse files
committedAug 10, 2020
Initial release
0 parents  commit 031e483

12 files changed

+201
-0
lines changed
 

‎.gitattributes

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/docs export-ignore

‎CHANGELOG.md

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Changelog
2+
All notable changes to this project will be documented in this file.
3+
4+
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
5+
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
6+
7+
## [1.0.0] - 2020-08-10
8+
9+
### Added
10+
- Initial release.

‎LICENSE.md

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) [year] [fullname]
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

‎Plugin/BypassTwoFactorAuth.php

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace MarkShust\DisableTwoFactorAuth\Plugin;
5+
6+
use Magento\Framework\App\Config\ScopeConfigInterface;
7+
use Magento\TwoFactorAuth\Model\TfaSession;
8+
9+
class BypassTwoFactorAuth
10+
{
11+
/** @var ScopeConfigInterface */
12+
private $scopeConfig;
13+
14+
public function __construct(
15+
ScopeConfigInterface $scopeConfig
16+
) {
17+
$this->scopeConfig = $scopeConfig;
18+
}
19+
20+
/**
21+
* If the TwoFactorAuth module Enable setting is set to false, always return true here so all requests bypass 2FA.
22+
* Otherwise, return the original result.
23+
*
24+
* @param TfaSession $subject
25+
* @param $result
26+
* @return bool
27+
*/
28+
public function afterIsGranted(TfaSession $subject, $result): bool
29+
{
30+
return !$this->scopeConfig->isSetFlag('twofactorauth/general/enable')
31+
? true
32+
: $result;
33+
}
34+
}

‎README.md

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<h1 align="center">MarkShust_DisableTwoFactorAuth</h1>
2+
3+
<div align="center">
4+
<p>Provides the ability to disable two-factor authentication.</p>
5+
<img src="https://img.shields.io/badge/magento-2.4-brightgreen.svg?logo=magento&longCache=true&style=flat-square" alt="Supported Magento Versions" />
6+
<a href="https://packagist.org/packages/markshust/magento2-module-disabletwofactorauth" target="_blank"><img src="https://img.shields.io/packagist/v/markshust/magento2-module-disabletwofactorauth.svg?style=flat-square" alt="Latest Stable Version" /></a>
7+
<a href="https://packagist.org/packages/markshust/magento2-module-disabletwofactorauth" target="_blank"><img src="https://poser.pugx.org/markshust/magento2-module-disabletwofactorauth/downloads" alt="Composer Downloads" /></a>
8+
<a href="https://GitHub.com/Naereen/StrapDown.js/graphs/commit-activity" target="_blank"><img src="https://img.shields.io/badge/maintained%3F-yes-brightgreen.svg?style=flat-square" alt="Maintained - Yes" /></a>
9+
<a href="https://opensource.org/licenses/MIT" target="_blank"><img src="https://img.shields.io/badge/license-MIT-blue.svg" /></a>
10+
</div>
11+
12+
## Table of contents
13+
14+
- [Summary](#summary)
15+
- [Installation](#installation)
16+
- [Usage](#usage)
17+
- [License](#license)
18+
19+
## Summary
20+
21+
With the release of Magento 2.4, two-factor authentication (also known as 2FA) became enabled by default, with no
22+
ability to disable it in either the admin or console. However, there are situations which may require 2FA to be disabled
23+
or temporarily turned off, such as within development or testing environments.
24+
25+
This module adds the missing toggle to turn 2FA on or off from the admin. It does this by hooking into the core code in
26+
a very seamless manner, just as would be done if this toggle existed in the core code. Installing this module should not
27+
open up any security holes, as it just works off of a simple config toggle which if not present, falls back to default
28+
functionality.
29+
30+
![Demo](https://raw.githubusercontent.com/markshust/magento2-module-disabletwofactorauth/master/docs/demo.png)
31+
32+
## Installation
33+
34+
```
35+
composer require markshust/magento2-module-disabletwofactorauth
36+
bin/magento module:enable MarkShust_DisableTwoFactorAuth
37+
bin/magento setup:upgrade
38+
```
39+
40+
## Usage
41+
42+
This module keeps 2FA enabled by default. This is to prevent any unexpected side effects or security loopholes from
43+
being introduced during automated installation processes.
44+
45+
After installing the module, one can disable 2FA by going to **Admin > Stores > Settings > Configuration >
46+
Security > 2FA**, and setting *Enable 2FA* to **No**.
47+
48+
This setting can also be toggled to a 1 or 0 to respectively enable or disable 2FA from the command-line console:
49+
50+
```
51+
bin/magento config:set twofactorauth/general/enable 0
52+
```
53+
54+
## License
55+
56+
[MIT](https://opensource.org/licenses/MIT)

‎composer.json

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"name": "markshust/magento2-module-disabletwofactorauth",
3+
"description": "The DisableTwoFactorAuth module provides the ability to disable two-factor authentication.",
4+
"require": {
5+
"php": ">=7.3",
6+
"magento/framework": ">=103"
7+
},
8+
"type": "magento2-module",
9+
"version": "1.0.0",
10+
"license": [
11+
"MIT"
12+
],
13+
"autoload": {
14+
"files": [
15+
"registration.php"
16+
],
17+
"psr-4": {
18+
"MarkShust\\DisableTwoFactorAuth\\": ""
19+
}
20+
}
21+
}

‎docs/demo.png

80.7 KB
Loading

‎etc/adminhtml/system.xml

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?xml version="1.0"?>
2+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
4+
<system>
5+
<section id="twofactorauth">
6+
<group id="general">
7+
<field id="enable" translate="label" type="select" sortOrder="1" showInDefault="1" canRestore="1">
8+
<label>Enable 2FA</label>
9+
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
10+
<comment>Warning: Enabling 2FA will immediately prompt admin user for OTP code.</comment>
11+
</field>
12+
<field id="force_providers">
13+
<depends>
14+
<field id="enable">1</field>
15+
</depends>
16+
</field>
17+
<field id="webapi_notification_url">
18+
<depends>
19+
<field id="enable">1</field>
20+
</depends>
21+
</field>
22+
</group>
23+
</section>
24+
</system>
25+
</config>

‎etc/config.xml

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0"?>
2+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Store:etc/config.xsd">
4+
<default>
5+
<twofactorauth>
6+
<general>
7+
<enable>1</enable>
8+
</general>
9+
</twofactorauth>
10+
</default>
11+
</config>

‎etc/di.xml

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0"?>
2+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
3+
<type name="Magento\TwoFactorAuth\Model\TfaSession">
4+
<plugin name="bypassTwoFactorAuth" type="MarkShust\DisableTwoFactorAuth\Plugin\BypassTwoFactorAuth"/>
5+
</type>
6+
</config>

‎etc/module.xml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0"?>
2+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
3+
<module name="MarkShust_DisableTwoFactorAuth">
4+
<sequence>
5+
<module name="Magento_TwoFactorAuth"/>
6+
</sequence>
7+
</module>
8+
</config>

‎registration.php

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
use Magento\Framework\Component\ComponentRegistrar;
3+
4+
ComponentRegistrar::register(
5+
ComponentRegistrar::MODULE,
6+
'MarkShust_DisableTwoFactorAuth',
7+
__DIR__
8+
);

0 commit comments

Comments
 (0)
Please sign in to comment.