Commits

Alexis Metaireau  committed b5df77f

Refactoring about utils function and decorators names.

To be sure to disambiguate, here are the usages:

* is_oauth_authenticated return a boolean, telling if the user is
authenticated or not.

* need_oauth_authentication is a decorator, to put on views that need to be
authenticated to be processed.

There is still a need of documentation about the usage of the logout method and
the decorators / utils functions.

  • Participants
  • Parent commits f3d4d3c

Comments (0)

Files changed (2)

File oauthclient/utils.py

 def get_consumer_token(identifier):
     return ConsumerToken.objects.get(identifier=identifier)
 
-def oauth_need_authentication(request, identifier, force=False):
-    """Authenticate user using oauth flow, if the an authentication does not
-    already exists.
+def is_oauth_authenticated(request, identifier):
+    """Tell if the user is authenticated to oauth, for the specified OAuth
+    provider identifier.
     
     """
     return not (identifier + '_oauth_token' and identifier + '_oauth_token_secret' in request.session)
     
-def is_oauthenticated(identifier, force=False):
+def need_oauth_authentication(identifier, force=False):
     """Decorator when oauth authentication is needed.
     
     If the user is not authenticated, redirect the user to the oauth 
     def wrapper(func):
         def wrapped(*args, **kwargs):
             request = args[0]
-            if force or oauth_need_authentication(request=request,
-                    identifier=identifier, force=force):
+            if force or is_oauth_authenticated(request=request,
+                    identifier=identifier):
                 return redirect('%s?next=%s' % (
                     reverse('oauth:request_token'), 
                     request.path))

File oauthclient/views.py

 import urlparse
 
 #oauthclient import
-from utils import is_oauthenticated
 from models import ConsumerToken, OAuthServer
 
 """These views are a generic way to do a three legged authentication with OAuth. 
 
 """
 
-def get_request_token(request, identifier):
+def get_request_token(request, identifier='default'):
     """First and second step of the three-legged OAuth flow:
     
     Request a request token to the OAuth server, and redirect the user on the
     request.session.save()
     return redirect(redirect_url)
     
-def access_token_ready(request, identifier):
+def access_token_ready(request, identifier='default'):
     """Last step of the OAuth three-legged flow.
 
     The user is redirected here once he allowed (or not) the application to 
         
     return render('authenticated.html', {})
     
-def logout(request, identifier):
+def logout(request, identifier='default'):
     """Destruct the active session oauth related keys.
     
     """