# -*- coding: utf-8 -*-
from setuptools import setup

package_dir = \
{'': 'src'}

packages = \
['appleauth']

package_data = \
{'': ['*']}

install_requires = \
['PyJWT>=2.6.0,<3.0.0',
 'djangorestframework>=3.14.0,<4.0.0',
 'requests>=2.28.1,<3.0.0']

setup_kwargs = {
    'name': 'appleauth',
    'version': '0.0.1',
    'description': 'Python library to implement Sign In with Apple in your Django backend.',
    'long_description': '# Apple Auth\n\nPython library to implement Sign In with Apple in your Django backend.\n\n## Table of Contents\n\n- [💾 Installation](#-installation)\n- [🍎 Apple docs](#-apple-docs)\n- [📝 Configuration](#-configuration)\n- [🚀 Usage](#-usage)\n- [🤖 Endpoints](#-endpoints)\n- [📜 Code Of Conduct](#code-of-conduct)\n\n### 💾 Installation\n\nTo easily install or upgrade to the latest release, use pip.\n\n```\n$ pip install appleauth\n```\n\n### 🍎 Apple docs\n\nFrom now on, some stuff is much better explained on the Apple docs, so when in doubt just check (if you haven\'t done so) the following documents:\n\n- [Sign In With Apple](https://developer.apple.com/sign-in-with-apple/get-started/)\n- [Request an authorization to the Sign in with Apple server](https://developer.apple.com/documentation/sign_in_with_apple/request_an_authorization_to_the_sign_in_with_apple_server)\n- [Generate and validate tokens](https://developer.apple.com/documentation/sign_in_with_apple/generate_and_validate_tokens)\n- [Revoke tokens](https://developer.apple.com/documentation/sign_in_with_apple/revoke_tokens)\n\n### 📝 Configuration\n\nTo start using the lib, some Apple Keys needs to be generated:\n\n- `client_id` (string)\n    - The identifier (App ID or Services ID) for your app. The identifier must not include your Team ID, to help prevent the possibility of exposing sensitive data to the end user.\n- `client_secret` (string)\n    - A secret JSON Web Token, generated by the developer, that uses the Sign in with Apple private key associated with your developer account. Authorization code and refresh token validation requests require this parameter.\n- `team_id` (string)\n    - Team ID of your developer account this can be found in your apple developer portal => identifier of your app => "App ID prefix".\n- `key_id` (string)\n    - The Key ID of the p8 file.\n\n### 🚀 Usage\n\nYou can install the library directly from PYPI using pip:\n\n```bash\npip install appleauth\n```\n\nEdit your settings.py file and update `INSTALLED_APPS` and `APPLE_CONFIG` with the appropriate keys generated via Apple Developer Portal:\n\n```python\nINSTALLED_APPS = [\n        ...,\n        "appleauth"\n]\n\n# Apple Config\nAPPLE_CONFIG = {\n    "APPLE_KEY_ID": "",\n    "APPLE_TEAM_ID": "",\n    "APPLE_CLIENT_ID": "",\n    "APPLE_PRIVATE_KEY": "",\n    "APPLE_REDIRECT_URL": "{{BASE URL}}/auth/apple/token", # https://127.0.0.1:8000/auth/apple/token\n    "APPLE_SCOPE": ["name", "email"],\n    "RESPONSE_HANDLER_CLASS": "users.services.AppleSignInResponseHandler",\n}\n```\n\nNOTE:\n\n- In the above config, `APPLE_REDIRECT_URL` is an endpoint which serves as a proxy to redirect the response of Apple server authorization to the `redirect_url` passed as query param while generating Authorization URL.\n- The response of authorization by Apple is a `POST request` where auth `code` and `state` is sent in request body. This endpoint converts the request body data to query params and send it to the redirect URL.\n\nCreate Response Handler Class and update path in `APPLE_CONFIG`, In this example we are considering it to be in `/users/services/AppleSignInResponseHandler`\n\n```python\nfrom appleauth.services import AppleAuthResponseHandler\n\nclass AppleSignInResponseHandler(AppleAuthResponseHandler):\n    def handle_fetch_or_create_user(self, request, user_dict):\n        email = user_dict.get("email", None)\n        apple_id = user_dict.get("apple_id", None)\n\n        # Implement a method to handle user creation\n        user,  is_created = get_or_create_user(email, apple_id)\n        context = {"is_created": is_created}\n\n        return user, context\n\n    def generate_response_json(self, user, extra_context):\n\n        # Implement a serializer to serialize user data\n        response = AuthUserSerializer(user, context=extra_context)\n\n        return response.data\n```\n\nNOTE:\n\n- `AuthUserSerializer` used in above ref. could be created as per app\'s functionality and contain fields which needs to be sent in response of authorization.\n- `get_or_create_user` method used in above code ref. could be created as per app\'s functionality.\n\nUpdate Routes:\n\n```python\nfrom rest_framework.routers import DefaultRouter\nfrom appleauth.apis import AppleAuthViewset\n\ndefault_router = DefaultRouter(trailing_slash=False)\n\ndefault_router.register("auth/apple", AppleAuthViewset, basename="apple-auth")\n\nurlpatterns = [...] + default_router.urls\n```\n\n### 🤖 Endpoints\n\n- Provides following APIs:\n    - [**Authorization URL API**](https://github.com/PrimedigitalGlobal/appleauth/blob/main/docs/endpoints.md#get-authorization-url)\n        - It generates Apple\'s `authorization-url` used to redirect to Apple\'s Authorization Server to request consent from resource owner.\n    - [**Authorize API**](https://github.com/PrimedigitalGlobal/appleauth/blob/main/docs/endpoints.md#authorize-user)\n        - Exchange authorization code for access token.\n        - Talk to resource server with access token and fetch user\'s profile information.\n    - [**Authorize IOS Token API**](https://github.com/PrimedigitalGlobal/appleauth/blob/main/docs/endpoints.md#authorize-ios-token)\n        - Verifies an ID Token issued by Apple\'s authorization server.\n        - Fetch user details from decoded token.\n\n**NOTE:** This documentation changes frequently, checkout the [changelog](changelog.md) for detailed breaking changes and features added.\n\n### Code of Conduct\n\nIn order to foster a kind, inclusive, and harassment-free community, we have a code of conduct, which can be found [here](CODE_OF_CONDUCT.md). We ask you to treat everyone as a smart human programmer that shares an interest in Python and Apple Pass Generator with you.\n',
    'author': 'Primedigital Global',
    'author_email': 'oss@primedigital.tech',
    'maintainer': 'Vikalp Jain',
    'maintainer_email': 'vikalp@primedigital.tech',
    'url': 'https://primedigitalglobal.github.io/appleauth',
    'package_dir': package_dir,
    'packages': packages,
    'package_data': package_data,
    'install_requires': install_requires,
    'python_requires': '>=3.9,<4.0',
}


setup(**setup_kwargs)
