Merge branch '29-oauth-provider-add-extra-info-button-to-show-urls' into 'master'
Resolve "OAuth Provider: Add extra info button to show URLs" Closes #29 See merge request BeryJu.org/passbook!15
This commit is contained in:
commit
5509ec9b0f
|
@ -57,6 +57,10 @@
|
|||
<a class="btn btn-default btn-sm"
|
||||
href="{{ href }}?back={{ request.get_full_path }}">{% trans name %}</a>
|
||||
{% endfor %}
|
||||
{% get_htmls provider as htmls %}
|
||||
{% for html in htmls %}
|
||||
{{ html|safe }}
|
||||
{% endfor %}
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
|
|
|
@ -5,6 +5,8 @@ from logging import getLogger
|
|||
from django import template
|
||||
from django.db.models import Model
|
||||
|
||||
from passbook.lib.utils.template import render_to_string
|
||||
|
||||
register = template.Library()
|
||||
LOGGER = getLogger(__name__)
|
||||
|
||||
|
@ -29,3 +31,24 @@ def get_links(model_instance):
|
|||
pass
|
||||
|
||||
return links
|
||||
|
||||
|
||||
@register.simple_tag(takes_context=True)
|
||||
def get_htmls(context, model_instance):
|
||||
"""Find all html_ methods on an object instance, run them and return as dict"""
|
||||
prefix = 'html_'
|
||||
htmls = []
|
||||
|
||||
if not isinstance(model_instance, Model):
|
||||
LOGGER.warning("Model %s is not instance of Model", model_instance)
|
||||
return htmls
|
||||
|
||||
try:
|
||||
for name, method in inspect.getmembers(model_instance, predicate=inspect.ismethod):
|
||||
if name.startswith(prefix):
|
||||
template, _context = method(context.get('request'))
|
||||
htmls.append(render_to_string(template, _context))
|
||||
except NotImplementedError:
|
||||
pass
|
||||
|
||||
return htmls
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
"""Oauth2 provider product extension"""
|
||||
|
||||
from django.shortcuts import reverse
|
||||
from django.utils.translation import gettext as _
|
||||
from oauth2_provider.models import AbstractApplication
|
||||
|
||||
|
@ -14,6 +15,20 @@ class OAuth2Provider(Provider, AbstractApplication):
|
|||
def __str__(self):
|
||||
return "OAuth2 Provider %s" % self.name
|
||||
|
||||
def html_setup_urls(self, request):
|
||||
"""return template and context modal with URLs for authorize, token, openid-config, etc"""
|
||||
return "oauth2_provider/setup_url_modal.html", {
|
||||
'provider': self,
|
||||
'authorize_url': request.build_absolute_uri(
|
||||
reverse('passbook_oauth_provider:oauth2-authorize')),
|
||||
'token_url': request.build_absolute_uri(
|
||||
reverse('passbook_oauth_provider:token')),
|
||||
'userinfo_url': request.build_absolute_uri(
|
||||
reverse('passbook_api:openid')),
|
||||
'openid_url': request.build_absolute_uri(
|
||||
reverse('passbook_oauth_provider:openid-discovery'))
|
||||
}
|
||||
|
||||
class Meta:
|
||||
|
||||
verbose_name = _('OAuth2 Provider')
|
||||
|
|
|
@ -0,0 +1,49 @@
|
|||
{% load i18n %}
|
||||
|
||||
<button class="btn btn-default btn-sm" data-toggle="modal" data-target="#{{ provider.pk }}">{% trans 'View Setup URLs' %}</button>
|
||||
<div class="modal fade" id="{{ provider.pk }}" tabindex="-1" role="dialog" aria-labelledby="{{ provider.pk }}Label" aria-hidden="true">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close" data-dismiss="modal" aria-hidden="true" aria-label="Close">
|
||||
<span class="pficon pficon-close"></span>
|
||||
</button>
|
||||
<h4 class="modal-title" id="{{ provider.pk }}Label">{% trans 'Setup URLs' %}</h4>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<form class="form-horizontal">
|
||||
<div class="form-group">
|
||||
<label class="col-sm-3 control-label">{% trans 'Authroize URL' %}</label>
|
||||
<div class="col-sm-9">
|
||||
<input type="text"class="form-control" readonly value="{{ authorize_url }}">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-sm-3 control-label">{% trans 'Token URL' %}</label>
|
||||
<div class="col-sm-9">
|
||||
<input type="text" class="form-control" readonly value="{{ token_url }}">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-sm-3 control-label">{% trans 'Userinfo Endpoint' %}</label>
|
||||
<div class="col-sm-9">
|
||||
<input type="text" class="form-control" readonly value="{{ userinfo_url }}">
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
<hr>
|
||||
<form class="form-horizontal">
|
||||
<div class="form-group">
|
||||
<label class="col-sm-3 control-label">{% trans 'OpenID Configuration URL' %}</label>
|
||||
<div class="col-sm-9">
|
||||
<input type="text"class="form-control" readonly value="{{ openid_url }}">
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-primary" data-dismiss="modal">{% trans 'Close' %}</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
Reference in a new issue