Skip to content

Commit

Permalink
Merge pull request #8 from aldryn/fixes
Browse files Browse the repository at this point in the history
fixes
  • Loading branch information
Chive committed Feb 24, 2016
2 parents ad8a786 + 08c7174 commit a2da3e9
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 12 deletions.
8 changes: 4 additions & 4 deletions simple_sso/sso_server/migrations/0001_initial.py
Expand Up @@ -19,16 +19,16 @@ class Migration(migrations.Migration):
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('name', models.CharField(unique=True, max_length=100)),
('private_key', models.CharField(default=simple_sso.sso_server.models.SecretKeyGenerator(b'private_key'), unique=True, max_length=64)),
('public_key', models.CharField(default=simple_sso.sso_server.models.SecretKeyGenerator(b'public_key'), unique=True, max_length=64)),
('private_key', models.CharField(default=simple_sso.sso_server.models.ConsumerSecretKeyGenerator(b'private_key'), unique=True, max_length=64)),
('public_key', models.CharField(default=simple_sso.sso_server.models.ConsumerSecretKeyGenerator(b'public_key'), unique=True, max_length=64)),
],
),
migrations.CreateModel(
name='Token',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('request_token', models.CharField(default=simple_sso.sso_server.models.SecretKeyGenerator(b'request_token'), unique=True, max_length=64)),
('access_token', models.CharField(default=simple_sso.sso_server.models.SecretKeyGenerator(b'access_token'), unique=True, max_length=64)),
('request_token', models.CharField(default=simple_sso.sso_server.models.TokenSecretKeyGenerator(b'request_token'), unique=True, max_length=64)),
('access_token', models.CharField(default=simple_sso.sso_server.models.TokenSecretKeyGenerator(b'access_token'), unique=True, max_length=64)),
('timestamp', models.DateTimeField(default=datetime.datetime.now)),
('redirect_to', models.CharField(max_length=255)),
('consumer', models.ForeignKey(related_name='tokens', to='sso_server.Consumer')),
Expand Down
6 changes: 1 addition & 5 deletions simple_sso/sso_server/models.py
Expand Up @@ -8,6 +8,7 @@
from ..utils import gen_secret_key


@deconstructible
class SecretKeyGenerator(object):
"""
Helper to give default values to Client.secret and Client.key
Expand All @@ -22,17 +23,12 @@ def __call__(self):
key = gen_secret_key(64)
return key

def __eq__(self, other):
return self.field == other.field


@deconstructible
class ConsumerSecretKeyGenerator(SecretKeyGenerator):
def get_model(self):
return Consumer


@deconstructible
class TokenSecretKeyGenerator(SecretKeyGenerator):
def get_model(self):
return Token
Expand Down
7 changes: 4 additions & 3 deletions simple_sso/sso_server/server.py
Expand Up @@ -5,6 +5,7 @@
from django.contrib.admin.options import ModelAdmin
from django.core.urlresolvers import reverse
from django.http import (HttpResponseForbidden, HttpResponseBadRequest, HttpResponseRedirect, QueryDict)
from django.utils import timezone
from django.views.generic.base import View
from itsdangerous import URLSafeTimedSerializer
from simple_sso.sso_server.models import Token, Consumer
Expand Down Expand Up @@ -39,10 +40,10 @@ class AuthorizeView(View):
"""
The client get's redirected to this view with the `request_token` obtained
by the Request Token Request by the client application beforehand.
This view checks if the user is logged in on the server application and if
that user has the necessary rights.
If the user is not logged in, the user is prompted to log in.
"""
server = None
Expand Down Expand Up @@ -73,7 +74,7 @@ def token_timeout(self):
return HttpResponseForbidden('Token timed out')

def check_token_timeout(self):
delta = datetime.datetime.now() - self.token.timestamp
delta = timezone.now() - self.token.timestamp
if delta > self.server.token_timeout:
self.token.delete()
return False
Expand Down

0 comments on commit a2da3e9

Please sign in to comment.