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 hashes)

Uploaded Source

Built Distribution

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

Uploaded Python 3

Supported by

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