Add default package settings. Edit README.

This commit is contained in:
juanifioren 2015-01-28 14:50:14 -03:00
parent e268c1c047
commit c323b0829b
4 changed files with 40 additions and 7 deletions

View file

@ -46,9 +46,18 @@ Add the provider urls.
# ... # ...
) )
Finally, add a login view and ensure that has the same url defined in `LOGIN_URL` setting. ********
Settings
********
See: https://docs.djangoproject.com/en/1.7/ref/settings/#login-url .. code:: python
# REQUIRED. Your server provider url.
SITE_URL = 'http://localhost:8000'
# REQUIRED.
# See: https://docs.djangoproject.com/en/1.7/ref/settings/#login-url
LOGIN_URL = '/accounts/login/'
******************** ********************
Create User & Client Create User & Client
@ -61,7 +70,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='confidential', response_type='code', redirect_uris=['http://example.com/']) >>> c = Client(name='Some Client', client_id='123', client_secret='456', response_type='code', redirect_uris=['http://example.com/'])
>>> c.save() >>> c.save()
******************* *******************

View file

@ -3,6 +3,7 @@ from openid_provider.lib.errors import *
from openid_provider.lib.utils.params import * from openid_provider.lib.utils.params import *
from openid_provider.lib.utils.token import * from openid_provider.lib.utils.token import *
from openid_provider.models import * from openid_provider.models import *
from openid_provider import settings
import urllib import urllib
@ -54,7 +55,7 @@ class TokenEndpoint(object):
id_token_dic = create_id_token_dic( id_token_dic = create_id_token_dic(
self.code.user, self.code.user,
'http://localhost:8000', # TODO: Add this into settings. settings.get('SITE_URL'),
self.client.client_id) self.client.client_id)
token = create_token( token = create_token(

View file

@ -0,0 +1,23 @@
from django.conf import settings
class default_settings(object):
# Here goes all the package default settings.
LOGIN_URL = None
SITE_URL = None
def get(name):
'''
Helper function to use inside the package.
'''
try:
value = getattr(default_settings, name)
value = getattr(settings, name)
except AttributeError:
if value == None:
raise Exception('You must set ' + name + ' in your settings.')
return value

View file

@ -1,4 +1,3 @@
from django.conf import settings
from django.contrib.auth import REDIRECT_FIELD_NAME from django.contrib.auth import REDIRECT_FIELD_NAME
from django.contrib.auth.views import redirect_to_login from django.contrib.auth.views import redirect_to_login
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
@ -11,6 +10,7 @@ from openid_provider.lib.errors import *
from openid_provider.lib.endpoints.authorize import * from openid_provider.lib.endpoints.authorize import *
from openid_provider.lib.endpoints.token import * from openid_provider.lib.endpoints.token import *
from openid_provider.lib.endpoints.userinfo import * from openid_provider.lib.endpoints.userinfo import *
from openid_provider import settings
class AuthorizeView(View): class AuthorizeView(View):
@ -24,7 +24,7 @@ class AuthorizeView(View):
if request.user.is_authenticated(): if request.user.is_authenticated():
# This is for printing scopes in the form. # This is for printing scopes in form.
authorize.params.scope_str = ' '.join(authorize.params.scope) authorize.params.scope_str = ' '.join(authorize.params.scope)
context = { context = {
@ -36,7 +36,7 @@ class AuthorizeView(View):
else: else:
path = request.get_full_path() path = request.get_full_path()
return redirect_to_login( return redirect_to_login(
path, settings.LOGIN_URL, REDIRECT_FIELD_NAME) path, settings.get('LOGIN_URL'), REDIRECT_FIELD_NAME)
except (ClientIdError, RedirectUriError) as error: except (ClientIdError, RedirectUriError) as error:
context = { context = {