drf-totp


Namedrf-totp JSON
Version 0.1.4 PyPI version JSON
download
home_pageNone
SummaryTOTP (Time-based One-Time Password) authentication for Django REST Framework
upload_time2024-11-20 21:41:34
maintainerNone
docs_urlNone
authorNone
requires_python>=3.8
licenseMIT
keywords 2fa authentication django framework mfa rest totp
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # DRF-TOTP

TOTP (Time-based One-Time Password) authentication for Django REST Framework.

## Features

- Generate TOTP secrets for users
- Verify TOTP tokens
- Enable/disable TOTP authentication
- Check TOTP status
- Validate TOTP tokens

## Installation

```bash
pip install drf-totp
```

## Quick Start

1. Add "drf_totp" to your INSTALLED_APPS setting:

```python
INSTALLED_APPS = [
    ...
    'rest_framework',
    'drf_totp',
]
```

2. Include the TOTP URLconf in your project urls.py:

```python
path('auth/', include('drf_totp.urls')),
```

3. Run migrations:

```bash
python manage.py migrate
```

## Settings

Add these to your Django settings:

```python
# Optional: Set your TOTP issuer name (defaults to "drftotp")
TOTP_ISSUER_NAME = "Your App Name"
```

## API Endpoints

- `POST /auth/otp/generate/`: Generate new TOTP secret
- `POST /auth/otp/verify/`: Verify and enable TOTP
- `GET /auth/otp/status/`: Get TOTP status
- `POST /auth/otp/disable/`: Disable TOTP
- `POST /auth/otp/validate/`: Validate TOTP token

## Usage Example

```javascript
import axios from 'axios';

// Generate TOTP
export async function generateTotp() {
  try {
    const response = await axios.post('/auth/otp/generate/');
    const { secret, otpauth_url } = response.data;
    return { secret, otpauth_url };
  } catch (error) {
    console.error('Error generating TOTP:', error);
    throw error;
  }
}

// Verify TOTP
export async function verifyTotp(token) {
  try {
    const response = await axios.post('/auth/otp/verify/', { token });
    return response.data;
  } catch (error) {
    console.error('Error verifying TOTP:', error);
    throw error;
  }
}

// Check Status
export async function checkStatus() {
  try {
    const response = await axios.get('/auth/otp/status/');
    return response.data;
  } catch (error) {
    console.error('Error checking status:', error);
    throw error;
  }
}

// Validate TOTP
export async function validateTotp(token) {
  try {
    const response = await axios.post('/auth/otp/validate/', { token });
    return response.data;
  } catch (error) {
    console.error('Error validating TOTP:', error);
    throw error;
  }
}
```

## License

MIT License - see LICENSE file for details.
            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "drf-totp",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": "2fa, authentication, django, framework, mfa, rest, totp",
    "author": null,
    "author_email": "djv-mo <solutiond700@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/32/9f/bae81a0c31635d2caaa85c8cc3775be639fc01f02d23b5fcb70370f11b4c/drf_totp-0.1.4.tar.gz",
    "platform": null,
    "description": "# DRF-TOTP\n\nTOTP (Time-based One-Time Password) authentication for Django REST Framework.\n\n## Features\n\n- Generate TOTP secrets for users\n- Verify TOTP tokens\n- Enable/disable TOTP authentication\n- Check TOTP status\n- Validate TOTP tokens\n\n## Installation\n\n```bash\npip install drf-totp\n```\n\n## Quick Start\n\n1. Add \"drf_totp\" to your INSTALLED_APPS setting:\n\n```python\nINSTALLED_APPS = [\n    ...\n    'rest_framework',\n    'drf_totp',\n]\n```\n\n2. Include the TOTP URLconf in your project urls.py:\n\n```python\npath('auth/', include('drf_totp.urls')),\n```\n\n3. Run migrations:\n\n```bash\npython manage.py migrate\n```\n\n## Settings\n\nAdd these to your Django settings:\n\n```python\n# Optional: Set your TOTP issuer name (defaults to \"drftotp\")\nTOTP_ISSUER_NAME = \"Your App Name\"\n```\n\n## API Endpoints\n\n- `POST /auth/otp/generate/`: Generate new TOTP secret\n- `POST /auth/otp/verify/`: Verify and enable TOTP\n- `GET /auth/otp/status/`: Get TOTP status\n- `POST /auth/otp/disable/`: Disable TOTP\n- `POST /auth/otp/validate/`: Validate TOTP token\n\n## Usage Example\n\n```javascript\nimport axios from 'axios';\n\n// Generate TOTP\nexport async function generateTotp() {\n  try {\n    const response = await axios.post('/auth/otp/generate/');\n    const { secret, otpauth_url } = response.data;\n    return { secret, otpauth_url };\n  } catch (error) {\n    console.error('Error generating TOTP:', error);\n    throw error;\n  }\n}\n\n// Verify TOTP\nexport async function verifyTotp(token) {\n  try {\n    const response = await axios.post('/auth/otp/verify/', { token });\n    return response.data;\n  } catch (error) {\n    console.error('Error verifying TOTP:', error);\n    throw error;\n  }\n}\n\n// Check Status\nexport async function checkStatus() {\n  try {\n    const response = await axios.get('/auth/otp/status/');\n    return response.data;\n  } catch (error) {\n    console.error('Error checking status:', error);\n    throw error;\n  }\n}\n\n// Validate TOTP\nexport async function validateTotp(token) {\n  try {\n    const response = await axios.post('/auth/otp/validate/', { token });\n    return response.data;\n  } catch (error) {\n    console.error('Error validating TOTP:', error);\n    throw error;\n  }\n}\n```\n\n## License\n\nMIT License - see LICENSE file for details.",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "TOTP (Time-based One-Time Password) authentication for Django REST Framework",
    "version": "0.1.4",
    "project_urls": {
        "Homepage": "https://github.com/mohamed-alired/drf-totp",
        "Issues": "https://github.com/mohamed-alired/drf-totp/issues",
        "Repository": "https://github.com/mohamed-alired/drf-totp.git"
    },
    "split_keywords": [
        "2fa",
        " authentication",
        " django",
        " framework",
        " mfa",
        " rest",
        " totp"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "221e9e900fd01606e8239f7cf0b472483b49f548838e626f487e83957209b7be",
                "md5": "8c062adb7d5479373ed2f15e20374f17",
                "sha256": "5b466ac4e269c98a0d956d035224b584f7bb8ac27d156ea21372657f43f18d4b"
            },
            "downloads": -1,
            "filename": "drf_totp-0.1.4-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "8c062adb7d5479373ed2f15e20374f17",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 8057,
            "upload_time": "2024-11-20T21:41:33",
            "upload_time_iso_8601": "2024-11-20T21:41:33.331068Z",
            "url": "https://files.pythonhosted.org/packages/22/1e/9e900fd01606e8239f7cf0b472483b49f548838e626f487e83957209b7be/drf_totp-0.1.4-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "329fbae81a0c31635d2caaa85c8cc3775be639fc01f02d23b5fcb70370f11b4c",
                "md5": "b694a4c5c2d879a37be54f847bf84ad2",
                "sha256": "6d7c5223beaf86767e7383c79f60e514409440e0a5b1d8b3e7910fb9e4dc8eff"
            },
            "downloads": -1,
            "filename": "drf_totp-0.1.4.tar.gz",
            "has_sig": false,
            "md5_digest": "b694a4c5c2d879a37be54f847bf84ad2",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 6222,
            "upload_time": "2024-11-20T21:41:34",
            "upload_time_iso_8601": "2024-11-20T21:41:34.566302Z",
            "url": "https://files.pythonhosted.org/packages/32/9f/bae81a0c31635d2caaa85c8cc3775be639fc01f02d23b5fcb70370f11b4c/drf_totp-0.1.4.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-11-20 21:41:34",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "mohamed-alired",
    "github_project": "drf-totp",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "drf-totp"
}
        
Elapsed time: 0.35466s