Delete client creation stuff. (should not be in the package)
This commit is contained in:
parent
36f8f7939b
commit
4602905314
13 changed files with 7 additions and 342 deletions
|
@ -61,9 +61,7 @@ Then let's create a Client. Start django shell: ``python manage.py shell``.
|
||||||
.. code:: python
|
.. code:: python
|
||||||
|
|
||||||
>>> from openid_provider.models import Client
|
>>> from openid_provider.models import Client
|
||||||
>>> c = Client(name='Some Client', client_id='123', client_secret='456', client_type='public', response_type='code', redirect_uris=['http://example.com/'])
|
>>> c = Client(name='Some Client', client_id='123', client_secret='456', client_type='confidential', response_type='code', redirect_uris=['http://example.com/'])
|
||||||
>>> from django.contrib.auth.models import User
|
|
||||||
>>> c.user = User.objects.all()[0]
|
|
||||||
>>> c.save()
|
>>> c.save()
|
||||||
|
|
||||||
*******************
|
*******************
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
{% extends "openid_provider/base.html" %}
|
{% extends "base.html" %}
|
||||||
|
|
||||||
{% load i18n %}
|
{% load i18n %}
|
||||||
|
|
||||||
|
|
|
@ -1,70 +0,0 @@
|
||||||
{% load staticfiles %}
|
|
||||||
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html lang="es">
|
|
||||||
<head>
|
|
||||||
<meta charset="utf-8">
|
|
||||||
<title>OpenID Provider</title>
|
|
||||||
|
|
||||||
<link href="//maxcdn.bootstrapcdn.com/bootswatch/3.3.1/spacelab/bootstrap.min.css" rel="stylesheet">
|
|
||||||
<style type="text/css">
|
|
||||||
body {
|
|
||||||
background-color: #fbfbfb;
|
|
||||||
padding-top: 90px;
|
|
||||||
padding-bottom: 30px;
|
|
||||||
}
|
|
||||||
.btn {
|
|
||||||
font-weight: bold;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
|
|
||||||
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
|
|
||||||
<!--[if lt IE 9]>
|
|
||||||
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
|
|
||||||
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
|
|
||||||
<![endif]-->
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
|
|
||||||
<!-- Fixed navbar -->
|
|
||||||
<nav class="navbar navbar-default navbar-fixed-top" role="navigation">
|
|
||||||
<div class="container">
|
|
||||||
<div class="navbar-header">
|
|
||||||
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
|
|
||||||
<span class="sr-only">Toggle navigation</span>
|
|
||||||
<span class="icon-bar"></span>
|
|
||||||
<span class="icon-bar"></span>
|
|
||||||
<span class="icon-bar"></span>
|
|
||||||
</button>
|
|
||||||
<a class="navbar-brand" href="#">OpenID Provider</a>
|
|
||||||
</div>
|
|
||||||
{% if user.is_authenticated %}
|
|
||||||
<div id="navbar" class="navbar-collapse collapse">
|
|
||||||
<ul class="nav navbar-nav navbar-right">
|
|
||||||
<li class="dropdown">
|
|
||||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">{{ user.email }} <span class="caret"></span></a>
|
|
||||||
<ul class="dropdown-menu" role="menu">
|
|
||||||
<li><a href="#">Profile</a></li>
|
|
||||||
{% if user.is_staff %}
|
|
||||||
<li class="divider"></li>
|
|
||||||
<li><a href="{% url 'openid_provider:client_list' %}">Clients</a></li>
|
|
||||||
{% endif %}
|
|
||||||
<li class="divider"></li>
|
|
||||||
<li><a href="{% url 'openid_provider:logout' %}">Logout</a></li>
|
|
||||||
</ul>
|
|
||||||
</li>
|
|
||||||
</ul>
|
|
||||||
</div><!--/.nav-collapse -->
|
|
||||||
{% endif %}
|
|
||||||
</div>
|
|
||||||
</nav>
|
|
||||||
|
|
||||||
<div class="container">
|
|
||||||
{% block content %}{% endblock %}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
|
|
||||||
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/js/bootstrap.min.js"></script>
|
|
||||||
|
|
||||||
</body>
|
|
||||||
</html>
|
|
|
@ -1,50 +0,0 @@
|
||||||
{% extends "openid_provider/base.html" %}
|
|
||||||
|
|
||||||
{% load i18n %}
|
|
||||||
|
|
||||||
{% block content %}
|
|
||||||
|
|
||||||
<div class="row">
|
|
||||||
<div class="col-md-6 col-md-offset-3">
|
|
||||||
<div class="panel panel-default">
|
|
||||||
<div class="panel-heading">
|
|
||||||
<h3 class="panel-title">Create new client</h3>
|
|
||||||
</div>
|
|
||||||
<div class="panel-body">
|
|
||||||
{% if error %}
|
|
||||||
<div class="alert alert-danger" role="alert"><strong>Something was wrong.</strong> Try again please.</div>
|
|
||||||
{% endif %}
|
|
||||||
<form action="" method="post">
|
|
||||||
{% csrf_token %}
|
|
||||||
<div class="form-group">
|
|
||||||
<label>Name</label>
|
|
||||||
<input name="name" type="text" class="form-control" placeholder="Some Client">
|
|
||||||
</div>
|
|
||||||
<div class="form-group">
|
|
||||||
<label>Client Type</label>
|
|
||||||
<select name="client_type" class="form-control">
|
|
||||||
<option value="confidential">Confidential</option>
|
|
||||||
<option value="public">Public</option>
|
|
||||||
</select>
|
|
||||||
</div>
|
|
||||||
<div class="form-group">
|
|
||||||
<label>Response Type</label>
|
|
||||||
<select name="response_type" class="form-control">
|
|
||||||
<option value="code">code (Authorization Code Flow)</option>
|
|
||||||
<option value="id_token">id_token (Implicit Flow)</option>
|
|
||||||
<option value="id_token token">id_token token (Implicit Flow)</option>
|
|
||||||
</select>
|
|
||||||
</div>
|
|
||||||
<div class="form-group">
|
|
||||||
<label>Redirect URIs</label>
|
|
||||||
<textarea name="redirect_uris" class="form-control" rows="3" placeholder="Complete URL's. Separated with new lines."></textarea>
|
|
||||||
</div>
|
|
||||||
<input type="submit" class="btn btn-success btn-block" value="OK" />
|
|
||||||
<br><a href="{% url 'openid_provider:client_list' %}"><span class="glyphicon glyphicon-arrow-left" aria-hidden="true"></span> Go Back</a>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{% endblock %}
|
|
|
@ -1,47 +0,0 @@
|
||||||
{% extends "openid_provider/base.html" %}
|
|
||||||
|
|
||||||
{% load i18n %}
|
|
||||||
|
|
||||||
{% block content %}
|
|
||||||
|
|
||||||
<div class="row">
|
|
||||||
<div class="col-md-6 col-md-offset-3">
|
|
||||||
<div class="panel panel-default">
|
|
||||||
<div class="panel-heading">
|
|
||||||
<h3 class="panel-title">{{ object.name }}</h3>
|
|
||||||
</div>
|
|
||||||
<div class="panel-body">
|
|
||||||
<h4>ID</h4>
|
|
||||||
<div class="well well-sm">{{ object.client_id }}</div>
|
|
||||||
<h4>SECRET</h4>
|
|
||||||
<div class="well well-sm">{{ object.client_secret }}</div>
|
|
||||||
|
|
||||||
<table class="table table-bordered">
|
|
||||||
<tr>
|
|
||||||
<th scope="row">User</th>
|
|
||||||
<td>{{ object.user.email }}</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<th scope="row">Client Type</th>
|
|
||||||
<td>{{ object.client_type }}</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<th scope="row">Response Type</th>
|
|
||||||
<td>{{ object.response_type }}</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<th scope="row">Redirect URIs</th>
|
|
||||||
<td>{{ object.redirect_uris|join:', ' }} </td>
|
|
||||||
</tr>
|
|
||||||
</table>
|
|
||||||
<div class="btn-group btn-group btn-group-justified" role="group">
|
|
||||||
<a class="btn btn-danger">Delete</a>
|
|
||||||
<a class="btn btn-success">Edit</a>
|
|
||||||
</div>
|
|
||||||
<br><a href="{% url 'openid_provider:client_list' %}"><span class="glyphicon glyphicon-arrow-left" aria-hidden="true"></span> Go Back</a>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{% endblock %}
|
|
|
@ -1,40 +0,0 @@
|
||||||
{% extends "openid_provider/base.html" %}
|
|
||||||
|
|
||||||
{% load i18n %}
|
|
||||||
|
|
||||||
{% block content %}
|
|
||||||
|
|
||||||
<div class="row">
|
|
||||||
<div class="col-md-3 col-md-offset-1">
|
|
||||||
<div class="panel panel-default">
|
|
||||||
<div class="panel-body">
|
|
||||||
<ul class="list-group">
|
|
||||||
<li class="list-group-item">
|
|
||||||
<span class="badge">{{ object_list.count }}</span>
|
|
||||||
<strong>Total</strong>
|
|
||||||
</li>
|
|
||||||
</ul>
|
|
||||||
<a href="{% url 'openid_provider:client_create' %}" class="btn btn-success btn-block">New Client</a>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="col-md-7">
|
|
||||||
<div class="panel panel-default">
|
|
||||||
<div class="panel-heading">
|
|
||||||
<h3 class="panel-title">Clients</h3>
|
|
||||||
</div>
|
|
||||||
<div class="panel-body">
|
|
||||||
<p>{% trans 'Click on the client you want to see.' %}</p>
|
|
||||||
<div class="list-group">
|
|
||||||
{% for client in object_list %}
|
|
||||||
<a href="{% url 'openid_provider:client_detail' client.id %}" class="list-group-item">{{ client.name }}<span class="badge">{{ client.default_redirect_uri }}</span></a>
|
|
||||||
{% empty %}
|
|
||||||
<div class="list-group-item">No clients yet.</div>
|
|
||||||
{% endfor %}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{% endblock %}
|
|
|
@ -1,4 +1,4 @@
|
||||||
{% extends "openid_provider/base.html" %}
|
{% extends "base.html" %}
|
||||||
|
|
||||||
{% load i18n %}
|
{% load i18n %}
|
||||||
|
|
||||||
|
|
|
@ -1,40 +0,0 @@
|
||||||
{% extends "openid_provider/base.html" %}
|
|
||||||
|
|
||||||
{% load i18n %}
|
|
||||||
|
|
||||||
{% block content %}
|
|
||||||
|
|
||||||
<div class="row">
|
|
||||||
<div class="col-md-4 col-md-offset-4">
|
|
||||||
<div class="panel panel-default">
|
|
||||||
<div class="panel-body">
|
|
||||||
<h2>Please sign in</h2>
|
|
||||||
<hr>
|
|
||||||
{% if form.errors %}
|
|
||||||
<div class="alert alert-danger" role="alert">Username and password mismatch.</div>
|
|
||||||
{% endif %}
|
|
||||||
<form accept-charset="UTF-8" role="form" method="post" action="{% url 'openid_provider:login' %}">
|
|
||||||
{% csrf_token %}
|
|
||||||
<fieldset>
|
|
||||||
<div class="form-group">
|
|
||||||
<input class="form-control" placeholder="Username" name="username" type="text">
|
|
||||||
</div>
|
|
||||||
<div class="form-group">
|
|
||||||
<input class="form-control" placeholder="Password" name="password" type="password" value="">
|
|
||||||
</div>
|
|
||||||
<div class="checkbox">
|
|
||||||
<label>
|
|
||||||
<input name="remember" type="checkbox" value="Remember Me"> Remember Me
|
|
||||||
</label>
|
|
||||||
</div>
|
|
||||||
<input type="hidden" name="next" value="{% if next %}{{ next }}{% else %}/openid/profile/{% endif %}" />
|
|
||||||
|
|
||||||
<input class="btn btn-primary btn-block" type="submit" value="OK">
|
|
||||||
</fieldset>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{% endblock %}
|
|
|
@ -1,19 +0,0 @@
|
||||||
{% extends "openid_provider/base.html" %}
|
|
||||||
|
|
||||||
{% load i18n %}
|
|
||||||
|
|
||||||
{% block content %}
|
|
||||||
|
|
||||||
<div class="row">
|
|
||||||
<div class="col-md-4 col-md-offset-4">
|
|
||||||
<div class="panel panel-default">
|
|
||||||
<div class="panel-body" >
|
|
||||||
<h2>{{ title }}</h2>
|
|
||||||
<p>{% trans "Thanks for spending some quality time with the Web site today." %}</p>
|
|
||||||
<p><a href="{% url 'openid_provider:login' %}">{% trans 'Log in again' %}</a></p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{% endblock %}
|
|
|
@ -1,20 +1,12 @@
|
||||||
from django.conf.urls import patterns, include, url
|
from django.conf.urls import patterns, include, url
|
||||||
from django.views.decorators.csrf import csrf_exempt
|
from django.views.decorators.csrf import csrf_exempt
|
||||||
|
from openid_provider.views import *
|
||||||
|
|
||||||
from openid_provider.views import clients
|
|
||||||
from openid_provider.views import endpoints
|
|
||||||
|
|
||||||
urlpatterns = patterns('',
|
urlpatterns = patterns('',
|
||||||
|
|
||||||
url(r'^authorize/$', endpoints.AuthorizeView.as_view(), name='authorize'),
|
url(r'^authorize/$', AuthorizeView.as_view(), name='authorize'),
|
||||||
url(r'^token/$', csrf_exempt(endpoints.TokenView.as_view()), name='token'),
|
url(r'^token/$', csrf_exempt(TokenView.as_view()), name='token'),
|
||||||
url(r'^userinfo/$', csrf_exempt(endpoints.userinfo), name='userinfo'),
|
url(r'^userinfo/$', csrf_exempt(userinfo), name='userinfo'),
|
||||||
|
|
||||||
url(r'^login/$', 'django.contrib.auth.views.login', { 'template_name': 'openid_provider/login.html' }, name='login'),
|
|
||||||
url(r'^logout/$', 'django.contrib.auth.views.logout', { 'template_name': 'openid_provider/logout.html' }, name='logout'),
|
|
||||||
|
|
||||||
url(r'^clients/$', clients.ClientListView.as_view(), name='client_list'),
|
|
||||||
url(r'^clients/(?P<pk>[\d]+)/$', clients.ClientDetailView.as_view(), name='client_detail'),
|
|
||||||
url(r'^clients/create/$', clients.client_create, name='client_create'),
|
|
||||||
|
|
||||||
)
|
)
|
|
@ -1,59 +0,0 @@
|
||||||
from django.shortcuts import redirect
|
|
||||||
from django.shortcuts import render
|
|
||||||
from django.utils.decorators import method_decorator
|
|
||||||
from django.views.generic.detail import DetailView
|
|
||||||
from django.views.generic.edit import CreateView
|
|
||||||
from django.views.generic.list import ListView
|
|
||||||
from openid_provider.lib.utils.decorators import staff_required
|
|
||||||
from openid_provider.models import Client
|
|
||||||
from random import random
|
|
||||||
import uuid
|
|
||||||
|
|
||||||
|
|
||||||
class ClientListView(ListView):
|
|
||||||
|
|
||||||
model = Client
|
|
||||||
|
|
||||||
@method_decorator(staff_required)
|
|
||||||
def dispatch(self, *args, **kwargs):
|
|
||||||
return super(ClientListView, self).dispatch(*args, **kwargs)
|
|
||||||
|
|
||||||
class ClientDetailView(DetailView):
|
|
||||||
|
|
||||||
model = Client
|
|
||||||
|
|
||||||
@method_decorator(staff_required)
|
|
||||||
def dispatch(self, *args, **kwargs):
|
|
||||||
return super(ClientListView, self).dispatch(*args, **kwargs)
|
|
||||||
|
|
||||||
@staff_required
|
|
||||||
def client_create(request):
|
|
||||||
|
|
||||||
error = False
|
|
||||||
|
|
||||||
if request.method == 'POST':
|
|
||||||
|
|
||||||
try:
|
|
||||||
client = Client()
|
|
||||||
|
|
||||||
client.name = request.POST.get('name')
|
|
||||||
client.client_type = request.POST.get('client_type')
|
|
||||||
client.response_type = request.POST.get('response_type')
|
|
||||||
client.redirect_uris = request.POST.get('redirect_uris')
|
|
||||||
|
|
||||||
client.client_id = str(random()).split('.')[1][:8]
|
|
||||||
client.client_secret = uuid.uuid4().hex
|
|
||||||
|
|
||||||
client.save()
|
|
||||||
|
|
||||||
return redirect('openid_provider:client_list')
|
|
||||||
|
|
||||||
except Exception as e:
|
|
||||||
print e
|
|
||||||
error = True
|
|
||||||
|
|
||||||
data = {
|
|
||||||
'error': error,
|
|
||||||
}
|
|
||||||
|
|
||||||
return render(request, 'openid_provider/client_create.html', data)
|
|
Loading…
Reference in a new issue