Skip to main content

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

  1. Install the library:

    pip install -U django-nice-auth
    
  2. Add the library to your Django project:

    Add 'niceauth' to your INSTALLED_APPS in the Django settings file.

    INSTALLED_APPS = [
        ...,
        'niceauth',
    ]
    
  3. 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
    
  4. 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:

  1. Get NICE Authentication Data

    • URL: /api/niceauth/

    • Method: GET or POST

    • Response:

      {
          "request_no": "REQUEST_NO",
          "enc_data": "ENCRYPTED_DATA",
          "integrity_value": "INTEGRITY_VALUE",
          "token_version_id": "TOKEN_VERSION_ID"
      }
      
  2. Get NICE Authentication URL

    • URL: /api/niceauth/url/

    • Method: GET or POST

    • 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"
      }
      
  3. Verify NICE Authentication Result

    • URL: /api/niceauth/verify/

    • Method: GET or POST

    • 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-nice-auth-0.1.11.tar.gz (14.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_nice_auth-0.1.11-py3-none-any.whl (19.5 kB view details)

Uploaded Python 3

File details

Details for the file django-nice-auth-0.1.11.tar.gz.

File metadata

  • Download URL: django-nice-auth-0.1.11.tar.gz
  • Upload date:
  • Size: 14.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.8.18

File hashes

Hashes for django-nice-auth-0.1.11.tar.gz
Algorithm Hash digest
SHA256 56396427c5cb2294f72edc173817c57ba3f878553f0b871b4992be7472a5adf6
MD5 22dce1501d1dc7527590f69a92a828d0
BLAKE2b-256 5c8ea7b3642d9dd22eaa1efa75f7ca240e021f932b7f8e242fb6f743ebccfc55

See more details on using hashes here.

File details

Details for the file django_nice_auth-0.1.11-py3-none-any.whl.

File metadata

File hashes

Hashes for django_nice_auth-0.1.11-py3-none-any.whl
Algorithm Hash digest
SHA256 5cea3730ad83473b2e6f2df3537d3fe0b8a0d1a67488434d129da11b59c6819a
MD5 5c0b7e45a8ff20838a3f1797634b3132
BLAKE2b-256 27a666c9ef40bb562f5b6318490c89d274677864921972b830b63c1c24529b24

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page