Coder Social home page Coder Social logo

django-tokenapi's People

Contributors

adamduren avatar bcnelson avatar dhilipsiva avatar jpulgarin avatar lablazer avatar numegil avatar omidraha avatar shebson avatar starou avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

django-tokenapi's Issues

200 response code when invalid request is made

If I make a request without a username or password, the returned status code is 200, while it should be 400. As a result, an incorrect request is treated as a correct one in the frontend.

Validate user before accessing attributes

ERROR Internal Server Error: /api/check
Traceback (most recent call last):
  File "/home/chillaranand/.virtualenvs/bar/lib/python3.5/site-packages/django/core/handlers/exception.py", line 41, in inner
    response = get_response(request)
  File "/home/chillaranand/.virtualenvs/bar/lib/python3.5/site-packages/django/core/handlers/base.py", line 249, in _legacy_get_response
    response = self._get_response(request)
  File "/home/chillaranand/.virtualenvs/bar/lib/python3.5/site-packages/django/core/handlers/base.py", line 187, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "/home/chillaranand/.virtualenvs/bar/lib/python3.5/site-packages/django/core/handlers/base.py", line 185, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/home/chillaranand/.virtualenvs/bar/lib/python3.5/site-packages/django/views/decorators/csrf.py", line 58, in wrapped_view
    return view_func(*args, **kwargs)
  File "/home/chillaranand/projects/foo/views.py", line 150, in check
    if token_generator.check_token(user, token) and user.is_active:
  File "/home/chillaranand/.virtualenvs/bar/lib/python3.5/site-packages/tokenapi/tokens.py", line 38, in check_token
    if not constant_time_compare(self._make_token_with_timestamp(user, ts), token):
  File "/home/chillaranand/.virtualenvs/bar/lib/python3.5/site-packages/tokenapi/tokens.py", line 54, in _make_token_with_timestamp
    value = (six.text_type(user.pk) + user.password + six.text_type(timestamp))
AttributeError: 'NoneType' object has no attribute 'pk'

JSONResponse should have a JSONSuccess subclass

right now, the only way to add a 'success' field is to manually add it to each response. JSONResponse should either have a success field by default, or there should be a JSONSuccess implementation.

Multiple authentication methods

I have a server that has HTTP Auth for non-production purposes, but I want the presence of the "user" and "token" params to take precedence over HTTP Auth in token_required().

I will end up changing token_required temporarily for my needs, but my suggestion here is to allow the developer to specify a preferred method if both HTTP Auth and Token auth is present.

TOKEN_TIMEOUT_DAYS

My tokens seem to expire after a couple days, despite having this set to a much larger number in settings.py

I looked through the code, but didn't find any references to TOKEN_TIMEOUT_DAYS.

A new session is created for every request

Whenever a new request is made to the server using a token, a new Django session is created. It shouldn't matter because sessions are not used here, but it could overwhelm the session store whether that is a database or an in-memory cache. This could be fixed by not calling the login() function in the decorator and setting request.user directly

missing imports in http.py

#
from django.http import HttpResponse
try:
    import simplejson as json
except ImportError:
    import json
#

# JSON helper functions

def JSONResponse(data, dump=True):
    return HttpResponse(
        json.dumps(data) if dump else data,
        mimetype='application/json',
    )

def JSONError(error_string):
    data = {
        'success': False,
        'errors': error_string,
    }
    return JSONResponse(data)

New release needed for Django 1.6

django-tokenapi 0.1.7 is broken in 1.6 because a deprecated API is used. The fix is actually already checked-in to master in commit d5cd7c1 but a new version needs to be pushed to PyPI. Can this be done?

200 response code when checking invalid token

In the same vein as #36, I should not get a 200 status code if I a token is invalid. As a rule of thumb, { success: false } should almost invariably return a non 2XX status code; after all, the request was not successful.

To support my case, I make requests to my API on the client side using axios, which returns ES6 promises. If I call Api.validateToken().then(success).catch(failure), I expect failure to be called if I supply an invalid token. At the moment, I have to check for response.data.success===false in the success callback since a 200 status is returned in any case.

I believe this is a major improvement to an otherwise straightforward Django module.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.