def oauth_enabled(decorated_function=None, scopes=None, **decorator_kwargs):
def curry_wrapper(wrapped_function):<EOL><INDENT>@wraps(wrapped_function)<EOL>def enabled_wrapper(request, *args, **kwargs):<EOL><INDENT>return_url = decorator_kwargs.pop('<STR_LIT>',<EOL>request.get_full_path())<EOL>user_oauth = django_util.UserOAuth2(request, scopes, return_url)<EOL>setattr(request, django_util.oauth2_settings.request_prefix,<EOL>user_oauth)<EOL>return wrapped_function(request, *args, **kwargs)<EOL><DEDENT>return enabled_wrapper<EOL><DEDENT>if decorated_function:<EOL><INDENT>return curry_wrapper(decorated_function)<EOL><DEDENT>else:<EOL><INDENT>return curry_wrapper<EOL><DEDENT>
Decorator to enable OAuth Credentials if authorized, and setup
    the oauth object on the request object to provide helper functions
    to start the flow otherwise.

    .. code-block:: python
       :caption: views.py
       :name: views_enabled3

       from oauth2client.django_util.decorators import oauth_enabled

       @oauth_enabled
       def optional_oauth2(request):
           if request.oauth.has_credentials():
               # this could be passed into a view
               # request.oauth.http is also initialized
               return HttpResponse("User email: {0}".format(
                                   request.oauth.credentials.id_token['email'])
           else:
               return HttpResponse('Here is an OAuth Authorize link:
               <a href="{0}">Authorize</a>'.format(
                   request.oauth.get_authorize_redirect()))


    Args:
        decorated_function: View function to decorate.
        scopes: Scopes to require, will default.
        decorator_kwargs: Can include ``return_url`` to specify the URL to
           return to after OAuth2 authorization is complete.

    Returns:
         The decorated view function.