From 6cb706fe0fbe7e7860b545816b6a07a0c35f773a Mon Sep 17 00:00:00 2001 From: Ignacio Fiorentino Date: Tue, 6 Sep 2016 11:36:19 -0300 Subject: [PATCH 1/7] Edit CHANGELOG. --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a45c483..43d2c0d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,9 @@ All notable changes to this project will be documented in this file. ### [Unreleased] +##### Added +- Polish translations. + ### [0.3.7] - 2016-08-31 ##### Added From a583648be2f4b62951acce3e680150983964d1d6 Mon Sep 17 00:00:00 2001 From: Ignacio Fiorentino Date: Tue, 6 Sep 2016 13:21:29 -0300 Subject: [PATCH 2/7] Add Access-Control-Allow-Origin to ProviderInfoView. --- oidc_provider/views.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/oidc_provider/views.py b/oidc_provider/views.py index e2a2b31..8e6366a 100644 --- a/oidc_provider/views.py +++ b/oidc_provider/views.py @@ -203,7 +203,10 @@ class ProviderInfoView(View): dic['token_endpoint_auth_methods_supported'] = ['client_secret_post', 'client_secret_basic'] - return JsonResponse(dic) + response = JsonResponse(dic) + response['Access-Control-Allow-Origin'] = '*' + + return response class JwksView(View): From 68d982369e3383ced523f6f7cd883523a97493a2 Mon Sep 17 00:00:00 2001 From: Ignacio Fiorentino Date: Tue, 6 Sep 2016 15:37:23 -0300 Subject: [PATCH 3/7] Add CORS fix to userinfo view. --- oidc_provider/views.py | 1 + 1 file changed, 1 insertion(+) diff --git a/oidc_provider/views.py b/oidc_provider/views.py index 8e6366a..912c8fc 100644 --- a/oidc_provider/views.py +++ b/oidc_provider/views.py @@ -171,6 +171,7 @@ def userinfo(request, *args, **kwargs): dic.update(extra_claims.create_response_dic()) response = JsonResponse(dic, status=200) + response['Access-Control-Allow-Origin'] = '*' response['Cache-Control'] = 'no-store' response['Pragma'] = 'no-cache' From 8bfbc60877cabae5b5ff3640a951365034d8f743 Mon Sep 17 00:00:00 2001 From: Ignacio Fiorentino Date: Tue, 6 Sep 2016 15:38:52 -0300 Subject: [PATCH 4/7] Add more doc. --- CHANGELOG.md | 4 ++ docs/index.rst | 1 + docs/sections/contribute.rst | 6 +-- docs/sections/examples.rst | 94 ++++++++++++++++++++++++++++++++++++ 4 files changed, 102 insertions(+), 3 deletions(-) create mode 100644 docs/sections/examples.rst diff --git a/CHANGELOG.md b/CHANGELOG.md index 43d2c0d..9faf401 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ All notable changes to this project will be documented in this file. ##### Added - Polish translations. +- Examples section in documentation. + +##### Fixed +- CORS in discovery and userinfo endpoint. ### [0.3.7] - 2016-08-31 diff --git a/docs/index.rst b/docs/index.rst index 43974a5..e0f7ff2 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -31,6 +31,7 @@ Contents: sections/userconsent sections/oauth2 sections/settings + sections/examples sections/contribute .. diff --git a/docs/sections/contribute.rst b/docs/sections/contribute.rst index f7a07e9..091d28a 100644 --- a/docs/sections/contribute.rst +++ b/docs/sections/contribute.rst @@ -31,7 +31,7 @@ Improve Documentation We use `Sphinx `_ for generate this documentation. I you want to add or modify something just: -* Install Sphinx ``pip install sphinx`` and this theme ``pip install sphinx-rtd-theme``. +* Install Sphinx (``pip install sphinx``) and the auto-build tool (``pip install sphinx-autobuild``). * Move inside the docs folder. ``cd docs/`` -* Generate the HTML. ``make html`` -* Open ``docs/_build/html/index.html`` on a browser. +* Generate and watch docs by running ``sphinx-autobuild . _build/``. +* Open ``http://127.0.0.1:8000`` on a browser. diff --git a/docs/sections/examples.rst b/docs/sections/examples.rst new file mode 100644 index 0000000..d1e8254 --- /dev/null +++ b/docs/sections/examples.rst @@ -0,0 +1,94 @@ +.. _examples: + +Examples +######## + +Pure JS client using Implicit Flow +================================== + +Testing OpenID Connect flow can be as simple as putting one file with a few functions on the client and calling the provider. Let me show. + +**01. Setup the provider** + +You can use the example project code to run your OIDC Provider at ``localhost:8000``. + +Go to the admin site and create a public client with a response_type ``id_token token`` and a redirect_uri ``http://localhost:3000``. + +.. note:: + Remember to create at least one **RSA Key** for the server. ``python manage.py creatersakey`` + +**02. Create the client** + +As relying party we are going to use a JS library created by Nat Sakimura. `Here is the article `_. + +**index.html**:: + + + + + + OIDC RP + + + + +
+

OpenID Connect RP Example

+ +
+ + + + + + + + + +.. note:: + Remember that you must set your client_id (line 21). + +**03. Make an authorization request** + +By clicking the login button an authorization request has been made to the provider. After you accept it, the provider will redirect back to your previously registered ``redirect_uri`` with all the tokens requested. + +**04. Requesting user information** + +Now having the access_token in your hands you can request the user information by making a request to the ``/userinfo`` endpoint of the provider. + +In this example we display information in the alert box. From d7b06ee3b41997a5f732a6c6c60501cfbe9a82fc Mon Sep 17 00:00:00 2001 From: Ignacio Fiorentino Date: Wed, 7 Sep 2016 12:30:20 -0300 Subject: [PATCH 5/7] Fix bug when creating first time client public. --- oidc_provider/admin.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/oidc_provider/admin.py b/oidc_provider/admin.py index 2a4fc61..71ee638 100644 --- a/oidc_provider/admin.py +++ b/oidc_provider/admin.py @@ -39,7 +39,7 @@ class ClientForm(ModelForm): elif (self.cleaned_data['client_type'] == 'confidential') and instance.client_secret: secret = instance.client_secret else: - if (instance.client_type == 'confidential'): + if (self.cleaned_data['client_type'] == 'confidential'): secret = md5(uuid4().hex.encode()).hexdigest() return secret @@ -47,7 +47,7 @@ class ClientForm(ModelForm): @admin.register(Client) class ClientAdmin(admin.ModelAdmin): - + form = ClientForm list_display = ['name', 'client_id', 'response_type', 'date_created'] readonly_fields = ['date_created'] @@ -56,14 +56,14 @@ class ClientAdmin(admin.ModelAdmin): @admin.register(Code) class CodeAdmin(admin.ModelAdmin): - + def has_add_permission(self, request): return False @admin.register(Token) class TokenAdmin(admin.ModelAdmin): - + def has_add_permission(self, request): return False From dd7d703ecb429c8f8ba56d936d1e66a5f1e328f1 Mon Sep 17 00:00:00 2001 From: Ignacio Fiorentino Date: Wed, 7 Sep 2016 12:32:03 -0300 Subject: [PATCH 6/7] Edit CHANGELOG. --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9faf401..864877a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ All notable changes to this project will be documented in this file. ##### Fixed - CORS in discovery and userinfo endpoint. +- Client type public bug when created using the admin. ### [0.3.7] - 2016-08-31 From 55c53b4bc7edf9643659cf976f47038605da04b7 Mon Sep 17 00:00:00 2001 From: Ignacio Fiorentino Date: Wed, 7 Sep 2016 16:02:31 -0300 Subject: [PATCH 7/7] Change templates of example project. --- example_project/README.md | 3 +- example_project/manage.py | 4 +- .../{provider_app => myapp}/__init__.py | 0 .../{provider_app => myapp}/settings.py | 6 +-- example_project/myapp/templates/base.html | 46 +++++++++++++++++ example_project/myapp/templates/home.html | 14 +++++ example_project/myapp/templates/login.html | 29 +++++++++++ .../templates/oidc_provider/authorize.html | 25 +++++++++ .../myapp/templates/oidc_provider/error.html | 12 +++++ .../{provider_app => myapp}/urls.py | 0 .../{provider_app => myapp}/wsgi.py | 2 +- .../provider_app/static/css/custom.css | 15 ------ .../provider_app/templates/base.html | 51 ------------------- .../provider_app/templates/home.html | 28 ---------- .../provider_app/templates/login.html | 40 --------------- .../templates/oidc_provider/authorize.html | 27 ---------- .../templates/oidc_provider/error.html | 16 ------ 17 files changed, 134 insertions(+), 184 deletions(-) rename example_project/{provider_app => myapp}/__init__.py (100%) rename example_project/{provider_app => myapp}/settings.py (94%) create mode 100644 example_project/myapp/templates/base.html create mode 100644 example_project/myapp/templates/home.html create mode 100644 example_project/myapp/templates/login.html create mode 100644 example_project/myapp/templates/oidc_provider/authorize.html create mode 100644 example_project/myapp/templates/oidc_provider/error.html rename example_project/{provider_app => myapp}/urls.py (100%) rename example_project/{provider_app => myapp}/wsgi.py (57%) delete mode 100644 example_project/provider_app/static/css/custom.css delete mode 100644 example_project/provider_app/templates/base.html delete mode 100644 example_project/provider_app/templates/home.html delete mode 100644 example_project/provider_app/templates/login.html delete mode 100644 example_project/provider_app/templates/oidc_provider/authorize.html delete mode 100644 example_project/provider_app/templates/oidc_provider/error.html diff --git a/example_project/README.md b/example_project/README.md index ab1fd6c..0a8dfef 100644 --- a/example_project/README.md +++ b/example_project/README.md @@ -1,6 +1,6 @@ # Example Project -![Example Project](http://i.imgur.com/IK3OZjx.png) +![Example Project](https://s17.postimg.org/4jjj8lavj/Screen_Shot_2016_09_07_at_15_58_43.png) Run your own OIDC provider in a second. This is a Django app with all the necessary things to work with `django-oidc-provider` package. @@ -31,6 +31,7 @@ Run your provider. ```bash $ python manage.py migrate $ python manage.py creatersakey +$ python manage.py createsuperuser $ python manage.py runserver ``` diff --git a/example_project/manage.py b/example_project/manage.py index ff8c2cf..7bf6f3d 100755 --- a/example_project/manage.py +++ b/example_project/manage.py @@ -2,8 +2,8 @@ import os import sys -if __name__ == "__main__": - os.environ.setdefault("DJANGO_SETTINGS_MODULE", "provider_app.settings") +if __name__ == '__main__': + os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'myapp.settings') from django.core.management import execute_from_command_line diff --git a/example_project/provider_app/__init__.py b/example_project/myapp/__init__.py similarity index 100% rename from example_project/provider_app/__init__.py rename to example_project/myapp/__init__.py diff --git a/example_project/provider_app/settings.py b/example_project/myapp/settings.py similarity index 94% rename from example_project/provider_app/settings.py rename to example_project/myapp/settings.py index d2a28af..bcde181 100644 --- a/example_project/provider_app/settings.py +++ b/example_project/myapp/settings.py @@ -20,7 +20,7 @@ INSTALLED_APPS = [ 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', - 'provider_app', + 'myapp', 'oidc_provider', ] @@ -50,9 +50,9 @@ TEMPLATES = [ }, ] -ROOT_URLCONF = 'provider_app.urls' +ROOT_URLCONF = 'myapp.urls' -WSGI_APPLICATION = 'provider_app.wsgi.application' +WSGI_APPLICATION = 'myapp.wsgi.application' # Database diff --git a/example_project/myapp/templates/base.html b/example_project/myapp/templates/base.html new file mode 100644 index 0000000..cca08d0 --- /dev/null +++ b/example_project/myapp/templates/base.html @@ -0,0 +1,46 @@ +{% load i18n staticfiles %} + + + + + + + + + + {% trans 'OpenID Provider Example' %} + + + + + + + + + +
+ {% block content %}{% endblock %} +
+ + + + + + diff --git a/example_project/myapp/templates/home.html b/example_project/myapp/templates/home.html new file mode 100644 index 0000000..c2f2518 --- /dev/null +++ b/example_project/myapp/templates/home.html @@ -0,0 +1,14 @@ +{% extends "base.html" %} +{% load i18n staticfiles %} + +{% block content %} + +
+
+

{% trans 'Welcome' %}{% if user.is_authenticated %} {{ user.username }}{% endif %}!

+

{% trans 'This is an example of an OpenID Connect 1.0 Provider. Built with the Django Framework and django-oidc-provider package.' %}

+

{% trans 'Create your clients' %}

+
+
+ +{% endblock %} diff --git a/example_project/myapp/templates/login.html b/example_project/myapp/templates/login.html new file mode 100644 index 0000000..906a2e4 --- /dev/null +++ b/example_project/myapp/templates/login.html @@ -0,0 +1,29 @@ +{% extends 'base.html' %} +{% load i18n %} + +{% block content %} + +
+
+
+ {% csrf_token %} + + {% if form.errors %} + + {% endif %} +
+ +
+
+ +
+
+ +
+
+
+
+ +{% endblock %} diff --git a/example_project/myapp/templates/oidc_provider/authorize.html b/example_project/myapp/templates/oidc_provider/authorize.html new file mode 100644 index 0000000..001896a --- /dev/null +++ b/example_project/myapp/templates/oidc_provider/authorize.html @@ -0,0 +1,25 @@ +{% extends 'base.html' %} +{% load i18n staticfiles %} + +{% block content %} + +
+
+

{% trans 'Request for Permission' %}

+

Client {{ client.name }} would like to access this information of you.

+
+ {% csrf_token %} + {{ hidden_inputs }} +
    + {% for scope in scopes %} +
  • {{ scope.name }}
    {{ scope.description }}
  • + {% endfor %} +
+
+ + +
+
+
+ +{% endblock %} diff --git a/example_project/myapp/templates/oidc_provider/error.html b/example_project/myapp/templates/oidc_provider/error.html new file mode 100644 index 0000000..77f8c89 --- /dev/null +++ b/example_project/myapp/templates/oidc_provider/error.html @@ -0,0 +1,12 @@ +{% extends 'base.html' %} + +{% block content %} + +
+
+

{{ error }}

+

{{ description }}

+
+
+ +{% endblock %} diff --git a/example_project/provider_app/urls.py b/example_project/myapp/urls.py similarity index 100% rename from example_project/provider_app/urls.py rename to example_project/myapp/urls.py diff --git a/example_project/provider_app/wsgi.py b/example_project/myapp/wsgi.py similarity index 57% rename from example_project/provider_app/wsgi.py rename to example_project/myapp/wsgi.py index cfd9ffa..91caa07 100644 --- a/example_project/provider_app/wsgi.py +++ b/example_project/myapp/wsgi.py @@ -1,5 +1,5 @@ import os -os.environ.setdefault("DJANGO_SETTINGS_MODULE", "provider_app.settings") +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'myapp.settings') from django.core.wsgi import get_wsgi_application application = get_wsgi_application() diff --git a/example_project/provider_app/static/css/custom.css b/example_project/provider_app/static/css/custom.css deleted file mode 100644 index 0f6eaa3..0000000 --- a/example_project/provider_app/static/css/custom.css +++ /dev/null @@ -1,15 +0,0 @@ -body { - background-color: #536dfe; - display: flex; - min-height: 100vh; - flex-direction: column; -} - -#main-container { - flex: 1 0 auto; - padding-top: 40px; -} - -footer { - padding-top: 0px !important; -} \ No newline at end of file diff --git a/example_project/provider_app/templates/base.html b/example_project/provider_app/templates/base.html deleted file mode 100644 index bc5903d..0000000 --- a/example_project/provider_app/templates/base.html +++ /dev/null @@ -1,51 +0,0 @@ -{% load i18n %} -{% load staticfiles %} - - - - - - - - - OpenID Provider Example - - - - - - - - - -
- {% block content %}{% endblock %} -
- - - - - - - - \ No newline at end of file diff --git a/example_project/provider_app/templates/home.html b/example_project/provider_app/templates/home.html deleted file mode 100644 index ec76385..0000000 --- a/example_project/provider_app/templates/home.html +++ /dev/null @@ -1,28 +0,0 @@ -{% extends "base.html" %} -{% load i18n %} -{% load staticfiles %} - -{% block content %} - -
-
-
-
-

Example of an OpenID Connect 1.0 Provider. Built with the Django Framework and django-oidc-provider package.

-

Start by creating your clients here.

-

Also check that you've created at least one server key, do it here.

- -
-
-
-
- -{% endblock %} diff --git a/example_project/provider_app/templates/login.html b/example_project/provider_app/templates/login.html deleted file mode 100644 index e9708ca..0000000 --- a/example_project/provider_app/templates/login.html +++ /dev/null @@ -1,40 +0,0 @@ -{% extends 'base.html' %} - -{% load i18n %} - -{% block content %} - -
-
-
-
-
- {% if form.errors %} -
Your username and password didn't match. Please try again.
- {% endif %} -
- {% csrf_token %} - -
-
- account_circle - - -
-
-
-
- lock - - -
-
- -
-
-
-
-
-
- -{% endblock %} \ No newline at end of file diff --git a/example_project/provider_app/templates/oidc_provider/authorize.html b/example_project/provider_app/templates/oidc_provider/authorize.html deleted file mode 100644 index 3e2a8b3..0000000 --- a/example_project/provider_app/templates/oidc_provider/authorize.html +++ /dev/null @@ -1,27 +0,0 @@ -{% extends 'base.html' %} - -{% block content %} - -
-
-

Request for Permission

-
-
-

Client {{ client.name }} would like to access this information of you.

-
- {% csrf_token %} - {{ hidden_inputs }} -
    - {% for scope in params.scope %} -
  • {{ scope | capfirst }}
  • - {% endfor %} -
- - -
-
-
-
-
- -{% endblock %} \ No newline at end of file diff --git a/example_project/provider_app/templates/oidc_provider/error.html b/example_project/provider_app/templates/oidc_provider/error.html deleted file mode 100644 index 31a221c..0000000 --- a/example_project/provider_app/templates/oidc_provider/error.html +++ /dev/null @@ -1,16 +0,0 @@ -{% extends 'base.html' %} - -{% block content %} - -
-
-
-
-

{{ error }}

-

{{ description }}

-
-
-
-
- -{% endblock %} \ No newline at end of file