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

packages = \
['okta_oauth2', 'okta_oauth2.tests']

package_data = \
{'': ['*'], 'okta_oauth2.tests': ['templates/okta_oauth2/*']}

install_requires = \
['Django>=1.11.0',
 'PyJWT>=1.7.1,<2.0.0',
 'python-jose[cryptography]>=3.1.0,<4.0.0',
 'requests>=2.22.0,<3.0.0']

setup_kwargs = {
    'name': 'django-okta-auth',
    'version': '0.5.4',
    'description': 'Django Authentication for Okta OpenID',
    'long_description': '# Django Okta Auth\n\n## Overview\nDjango Okta Auth is a library that acts as a client for the Okta OpenID Connect provider.\n\nThe library provides a set of views for login, logout and callback, an auth backend for authentication, and a middleware for token verification in requests.\n\nIt\'s heavily influenced by [okta-django-samples](https://github.com/zeekhoo-okta/okta-django-samples) but there\'s a few fundamental changes and further implementation of things like refresh tokens which weren\'t initially implemented.\n\nThis project is in no way affiliated with Okta.\n\n## Installation\n\nInstall from PyPI:\n\n    pip install django-okta-auth\n\n## Configuration\n\n### Install the App\n\nAdd `okta_oauth2.apps.OktaOauth2Config` to `INSTALLED_APPS`:\n\n    INSTALLED_APPS = (\n        ...,\n        \'okta_oauth2.apps.OktaOauth2Config\',\n        ...\n    )\n\n### Authentication Backend\n\nYou will need to install the authentication backend. This extends Django\'s default `ModelBackend` which uses the configured database for user storage, but overrides the `authenticate` method to accept the `auth_code` returned by Okta\'s `/authorize` API endpoint [as documented here](https://developer.okta.com/docs/reference/api/oidc/#authorize).  \n\nThe Authentication Backend should be configured as so:\n\n    AUTHENTICATION_BACKENDS = ("okta_oauth2.backend.OktaBackend",)\n\n### Middleware\n\nIf you wish to check for valid tokens on every request and refresh tokens automatically when they expire (you should), then you will need to install the provided middleware. Order of middleware is important and the `OktaMiddleware` must be below the `SessionMiddleware` and `AuthenticationMiddleware` to ensure that the session and the user are both on the request:\n\n    MIDDLEWARE = (\n        \'django.middleware.security.SecurityMiddleware\',\n        \'django.contrib.sessions.middleware.SessionMiddleware\',\n        \'django.middleware.common.CommonMiddleware\',\n        \'django.middleware.csrf.CsrfViewMiddleware\',\n        \'django.contrib.auth.middleware.AuthenticationMiddleware\',\n        \'django.contrib.messages.middleware.MessageMiddleware\',\n        \'django.middleware.clickjacking.XFrameOptionsMiddleware\',\n        \'okta_oauth2.middleware.OktaMiddleware\'\n    )\n\n### Update urls<span></span>.py\n\nAdd the `django-okta-auth` views to your `urls.py`. This will provide the `login`, `logout` and `callback` views which are required by the login flows.\n\n    from django.urls import include, path\n\n    urlpatterns = [\n        path(\'accounts/\', include(("okta_oauth2.urls", "okta_oauth2"), namespace="okta_oauth2")),\n    ]\n\n### Setup your Okta Application\n\nIn the Okta admin console create your application with the following steps:\n\n1. Click `Create New App`\n2. Choose the `Web` platform\n3. Choose the `OpenID Connect` Sign on method\n4. Click the `Create` button\n5. Give the application a name and choose a logo if desired\n6. Add the URL to the login view as defined in the previous section, eg. `http://localhost:8000/accounts/login/`\n7. Click the `Save` button\n8. In the General Settings of the application click edit and check `Authorization Code` and the `Refresh Token` under `Allowed grant types`.\n9. Save the settings\n10. Take note of the `Client ID` and the `Client secret` in the Client Credentials for use in the next section. It is important to note that the `Client secret` is confidential and under no circumstances should be exposed publicly.\n\n### Django Okta Settings\n\nDjango Okta Auth settings should be specified in your django `settings.py` as follows:\n\n    OKTA_AUTH = {\n        "ORG_URL": "https://your-org.okta.com/",\n        "ISSUER": "https://your-org.okta.com/oauth2/default",\n        "CLIENT_ID": "yourclientid",\n        "CLIENT_SECRET": "yourclientsecret",\n        "SCOPES": "openid profile email offline_access", # this is the default and can be omitted\n        "REDIRECT_URI": "http://localhost:8000/oauth2/callback",\n        "LOGIN_REDIRECT_URL": "/", # default\n        "CACHE_PREFIX": "okta", # default\n        "CACHE_ALIAS: "default", # default\n        "PUBLIC_NAMED_URLS": (), # default\n        "PUBLIC_URLS": (), # default\n    }\n\n### Login Template\n\nThe login view will render the `okta_oauth2/login.html` template. It will be passed the following information in the `config` template context variable:\n\n    {\n        "clientId": settings.OKTA_AUTH["CLIENT_ID"],\n        "url": settings.OKTA_AUTH["ORG_URL"],\n        "redirectUri": settings.OKTA_AUTH["REDIRECT_URI"],\n        "scope": settings.OKTA_AUTH["SCOPES"],\n        "issuer": settings.OKTA_AUTH["ISSUER"]\n    }\n\nThe easiest way to use this is to implement the [Okta Sign-In Widget](https://developer.okta.com/code/javascript/okta_sign-in_widget/) in your template.\n\nA minimal template for the login could be:\n\n```html\n<!DOCTYPE html>\n<html>\n    <head>\n        <meta charset="utf-8">\n        <meta name="viewport" content="width=device-width, initial-scale=1.0" />\n        <script src="https://global.oktacdn.com/okta-signin-widget/3.1.3/js/okta-sign-in.min.js" type="text/javascript"></script>\n        <link href="https://global.oktacdn.com/okta-signin-widget/3.1.3/css/okta-sign-in.min.css" type="text/css" rel="stylesheet"/>\n    </head>\n    <body>\n        <div id="okta-login-container"></div>\n\n        <script>\n        var oktaSignIn = new OktaSignIn({\n            logo: \'https://logo.clearbit.com/fakedetail.com\',\n            baseUrl: \'{{config.url}}\',\n            clientId: \'{{config.clientId}}\',\n            redirectUri: \'{{config.redirectUri}}\',\n            authParams: {\n                issuer: \'{{config.issuer}}\',\n                responseType: [\'code\'],\n                scopes: "{{config.scope}}".split(" ")\n            },\n        });\n        </script>\n\n    </body>\n</html>\n```\n\n## Settings Reference\n\n***ORG_URL***:\n\n*str*. URL Okta provides for your organization account. This is the URL that you log in to for the admin panel, minus the `-admin`. eg, if your admin URL is https://myorg-admin.okta.com/ then your `ORG_URL` should be: https://myorg.okta.com/\n\n***ISSUER***\n\n*str*. This is the URL for your Authorization Server. If you\'re using the default authorization server then this will be: `https://{ORG_URL}/oauth2/default`\n\n***CLIENT_ID***\n\n*str*. The Client ID provided by your Okta Application.\n\n***CLIENT_SECRET***\n\n*str*. The Client Secret provided by your Okta Application.\n\n***SCOPES***\n\n*str*. The scopes requested from the OpenID Authorization server. At the very least this needs to be `"openid profile email"` but if you want to use refresh tokens you will need `"openid profile email offline_access"`. This is the default.\n\nIf you want Okta to manage your groups then you should also include `groups` in your scopes.\n\n***REDIRECT_URI***\n\n*str*. This is the URL to the `callback` view that the okta Sign-In Widget will redirect the browser to after the username and password have been authorized. If the directions in the `urls.py` section of the documentation were followed and your django server is running on `localhost:8000` then this will be: http://localhost:8000/accounts/callback/\n\n***LOGIN_REDIRECT_URL***\n\n*str*. This is the URL to redirect to from the `callback` after a successful login. Defaults to `/`.\n\n***CACHE_PREFIX***\n\n*str*. The application will utilise the django cache to store public keys requested from Okta in an effort to minimise network round-trips and speed up authorization. This setting will control the prefix for the cache keys. Defaults to `okta`.\n\n***CACHE_ALIAS***\n\n*str*. Specify which django cache should be utilised for storing public keys. Defaults to `default`.\n\n***PUBLIC_NAMED_URLS***\n\n*List[str]*. A list or tuple of URL names that should be accessible without tokens. If you add a URL in this setting the middleware won\'t check for tokens. Default is: `[]`\n\n***PUBLIC_URLS***\n\n*List[str]*. A list or tuple of URL regular expressions that should be accessible without tokens. If you add a regex in this setting the middleware won\'t check matching paths for tokens. Default is `[]`.\n\n***SUPERUSER_GROUP***\n\n*str*. Members of this group will be created with the django `is_staff` and `is_superuser` flags set.\n\n***MANAGE_GROUPS***\n\n*bool*. If true the authentication backend will manage django groups for you.\n\n## License\n\nMIT License\n\nCopyright (c) 2020 Matt Magin\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the "Software"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n',
    'author': 'Matt Magin',
    'author_email': 'matt.magin@cmv.com.au',
    'maintainer': None,
    'maintainer_email': None,
    'url': 'https://github.com/AzMoo/django-okta-auth',
    'packages': packages,
    'package_data': package_data,
    'install_requires': install_requires,
    'python_requires': '>=3.6,<4.0',
}


setup(**setup_kwargs)
