A Django app for NICE authentication
Project description
django-nice-auth
A Django library for integrating NICE authentication services. This library provides an interface for generating authentication data, retrieving authentication URLs, and verifying authentication results.
Current version: 0.1.11
Overview
django-niceauth
is a Django library that provides an interface for interacting with the NICE authentication API. It supports obtaining tokens, generating encrypted tokens, and creating URLs for NICE authentication services.
Requirements
- Python 3.6+
- Django 3.0+
nice_auth
library
Installation
-
Install the library:
pip install -U django-nice-auth
-
Add the library to your Django project:
Add
'niceauth'
to yourINSTALLED_APPS
in the Django settings file.INSTALLED_APPS = [ ..., 'niceauth', ]
-
Set up your environment variables:
Create a
.env
file in the root directory and add the following configurations:NICE_AUTH_BASE_URL=https://svc.niceapi.co.kr:22001 NICE_CLIENT_ID=your_client_id NICE_CLIENT_SECRET=your_client_secret NICE_PRODUCT_ID=your_product_id NICE_RETURN_URL=https://yourdomain.com/verify NICE_AUTHTYPE=M NICE_POPUPYN=N
-
Apply the migrations:
python manage.py migrate
Configuration
Before using the library, you need to set up the necessary configuration values in your .env
file as shown above.
Usage
Models
The library includes the following models to store authentication requests and results:
NiceAuthRequest
: Stores the request data.NiceAuthResult
: Stores the result data.
API Endpoints
The library provides the following API endpoints:
-
Get NICE Authentication Data
-
URL:
/api/niceauth/
-
Method:
GET
orPOST
-
Response:
{ "request_no": "REQUEST_NO", "enc_data": "ENCRYPTED_DATA", "integrity_value": "INTEGRITY_VALUE", "token_version_id": "TOKEN_VERSION_ID" }
-
-
Get NICE Authentication URL
-
URL:
/api/niceauth/url/
-
Method:
GET
orPOST
-
Response:
{ "nice_auth_url": "https://nice.checkplus.co.kr/CheckPlusSafeModel/service.cb?m=service&token_version_id=TOKEN_VERSION_ID&enc_data=ENCRYPTED_DATA&integrity_value=INTEGRITY_VALUE" }
-
-
Verify NICE Authentication Result
-
URL:
/api/niceauth/verify/
-
Method:
GET
orPOST
-
Request Body:
{ "enc_data": "ENCRYPTED_DATA", "token_version_id": "TOKEN_VERSION_ID", "integrity_value": "INTEGRITY_VALUE" }
-
Response:
{ "resultcode": "0000", "requestno": "REQUEST_NO", "sitecode": "SITE_CODE", ... }
-
Example Usage
Initializing the Service
First, you need to initialize the NiceAuthService
with the necessary configuration values:
from nice_auth.services import NiceAuthService
service = NiceAuthService(
base_url=settings.NICE_AUTH_BASE_URL,
client_id=settings.NICE_CLIENT_ID,
client_secret=settings.NICE_CLIENT_SECRET,
product_id=settings.NICE_PRODUCT_ID,
return_url=settings.NICE_RETURN_URL,
authtype=settings.NICE_AUTHTYPE,
popupyn=settings.NICE_POPUPYN
)
### Getting NICE Authentication Data
```python
auth_data = service.get_nice_auth()
Getting NICE Authentication URL
nice_url = service.get_nice_auth_url()
Verifying NICE Authentication Result
result_data = service.verify_auth_result(enc_data, key, iv)
Running Tests
To run the tests, use the following command:
python manage.py test
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for django_nice_auth-0.1.11-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5cea3730ad83473b2e6f2df3537d3fe0b8a0d1a67488434d129da11b59c6819a |
|
MD5 | 5c0b7e45a8ff20838a3f1797634b3132 |
|
BLAKE2b-256 | 27a666c9ef40bb562f5b6318490c89d274677864921972b830b63c1c24529b24 |