api.py 783 Bytes
Newer Older
Gregory Martin committed
1
"""
2
Pipeline API METHODS
Gregory Martin committed
3 4 5 6 7 8 9 10 11 12

1. cheap-o token authorizer
This is a super hacky way to finish the Oauth2 Flow, but I need to move on
will get the token id from a url view, auth it, then push forward with a success bool

"""

import os
import sys

13 14
from oauth2_provider.models import AccessToken

Gregory Martin committed
15 16 17 18 19 20 21 22 23 24
from rest_framework.authtoken.models import Token
from django.contrib.auth.models import User


primary_directory = os.path.dirname(__file__)
sys.path.append(primary_directory)


def token_finisher(token_id):
    try:
25
        d = AccessToken.objects.get(token=token_id)
Gregory Martin committed
26 27 28 29 30 31 32 33 34 35
    except:
        return False

    d.user = User.objects.get(pk=1)
    d.save()
    try:
        token = Token.objects.create(user=d.user)
    except:
        token = Token.objects.get(user=d.user)
    return token.key