Templates

    You can override default templates located in folder and provide a custom layout. To override these templates you just need to create a folder named oauth2_provider inside your templates folder and, inside this folder, add a file that matches the name of the template you’re trying to override.

    The templates available are:

    If you just want a different look and feel you may only override this template. To inherit this template just add {% extends "oauth2_provider/base.html" %} in the first line of the other templates. This is what is done with the default templates.

    The blocks defined in it are:

    • title inside the HTML title tag;
    • css inside the head;
    • content in the body.

    Authorize is rendered in AuthorizationView (authorize/).

    This template gets passed the following context variables:

    • scopes - with the scopes requested by the application;

    Caution

    See DEFAULT_SCOPES to understand what is returned if no scopes are requested.

    • scopes_descriptions - with the descriptions for the scopes requested;
    • application - An Application object

    Note

    If you haven’t created your own Application Model (see how in ), you will get an AbstractApplication object.

    • client_id - Passed in the URI, already validated.
    • redirect_uri - Passed in the URI (optional), already validated.

    Note

    If it wasn’t provided on the request, the default one has been set (see ).

    • response_type - Passed in the URI, already validated.
    • form - An AllowForm with all the hidden fields already filled with the values above.

    Important

    Example (this is the default page you may find on templates/oauth2_provider/authorize.html):

    1. {% extends "oauth2_provider/base.html" %}
    2. {% load i18n %}
    3. {% block content %}
    4. <div class="block-center">
    5. {% if not error %}
    6. <form id="authorizationForm" method="post">
    7. <h3 class="block-center-heading">{% trans "Authorize" %} {{ application.name }}?</h3>
    8. {% csrf_token %}
    9. {% for field in form %}
    10. {% if field.is_hidden %}
    11. {{ field }}
    12. {% endif %}
    13. <p>{% trans "Application requires following permissions" %}</p>
    14. <ul>
    15. {% for scope in scopes_descriptions %}
    16. <li>{{ scope }}</li>
    17. {% endfor %}
    18. </ul>
    19. {{ form.errors }}
    20. {{ form.non_field_errors }}
    21. <div class="control-group">
    22. <div class="controls">
    23. <input type="submit" class="btn btn-large" value="Cancel"/>
    24. </div>
    25. </div>
    26. </form>
    27. {% else %}
    28. <h2>Error: {{ error.error }}</h2>
    29. <p>{{ error.description }}</p>
    30. {% endif %}
    31. </div>
    32. {% endblock %}

    The management templates are Django Admin Site alternatives to manage the Apps.

    All templates receive Application objects.

    Note

    If you haven’t created your own Application Model (see how in ), you will get an AbstractApplication object.

    application_list.html

    Rendered in ApplicationList (applications/). This class inherits django.views.generic.edit.ListView.

    This template gets passed the following template context variable:

    • applications - a with all the applications, may be None.

    application_form.html

    Rendered in ApplicationUpdate (applications/<pk>/update/). This class inherits django.views.generic.edit.UpdateView.

    This template gets passed the following template context variables:

    • application - the object.
    • form - a Form with the following fields:

      • client_id
      • client_secret
      • client_type
      • authorization_grant_type
      • redirect_uris

    Caution

    In the default implementation this template in extended by . Be sure to provide the same blocks if you are only overiding this template.

    application_registration_form.html

    Rendered in ApplicationRegistration (applications/register/). This class inherits django.views.generic.edit.CreateView.

    This template gets passed the following template context variable:

    • form - a with the following fields:

      • name
      • client_id
      • client_secret
      • client_type
      • authorization_grant_type
      • redirect_uris

    In the default implementation this template extends application_form.html.

    application_detail.html

    Rendered in ApplicationDetail (applications/<pk>/). This class inherits django.views.generic.edit.DetailView.

    This template gets passed the following template context variable:

    • application - the object.

    application_confirm_delete.html

    Rendered in ApplicationDelete (applications/<pk>/delete/). This class inherits django.views.generic.edit.DeleteView.

    This template gets passed the following template context variable:

    • application - the object.

    Important

    To override successfully this template you should provide a form that posts to the same URL, example: <form method="post" action="">

    Token

    All templates receive AccessToken objects.

    authorized-tokens.html

    Rendered in AuthorizedTokensListView (authorized_tokens/). This class inherits django.views.generic.edit.ListView.

    This template gets passed the following template context variable:

    • authorized_tokens - a with all the tokens that belong to applications that the user owns, may be None.

    Important

    To override successfully this template you should provide links to revoke the token, example: <a href="{% url 'oauth2_provider:authorized-token-delete' authorized_token.pk %}">revoke</a>

    authorized-token-delete.html

    Rendered in AuthorizedTokenDeleteView (authorized_tokens/<pk>/delete/). This class inherits django.views.generic.edit.DeleteView.

    This template gets passed the following template context variable:

    • authorized_token - the object.

    Important