def get_oauth_token(request):
    try:
        oauth_info = OAuth.get(consumer_key=request.POST['key'])
    except Process.DoesNotExist:
        try:
            oauth_info = OAuth.get(consumer_key = request.BODY['key'])
        except:
            return HttpResponseForbidden
    if oauth_info.consumer_secret == request.POST['secret']:
        pass
    elif oauth_info.consumer_secret == request.BODY['secret']:
        pass
    else:
        return HttpResponseForbidden
    oauth_info.token = ''.join(random.choice(string.ascii_letters + string.digits) for _ in range(45))
    oauth_info.save()
    return HttpResponse(json.dumps({'token_type': 'bearer', 'access_token': oauth_info.token}), content_type="application/json")
def get_oauth_token(request):
    try:
        oauth_info = OAuth.get(consumer_key=request.POST['key'])
    except Process.DoesNotExist:
        try:
            oauth_info = OAuth.get(consumer_key=request.BODY['key'])
        except:
            return HttpResponseForbidden
    if oauth_info.consumer_secret == request.POST['secret']:
        pass
    elif oauth_info.consumer_secret == request.BODY['secret']:
        pass
    else:
        return HttpResponseForbidden
    oauth_info.token = ''.join(
        random.choice(string.ascii_letters + string.digits) for _ in range(45))
    oauth_info.save()
    return HttpResponse(json.dumps({
        'token_type': 'bearer',
        'access_token': oauth_info.token
    }),
                        content_type="application/json")
示例#3
0
 def wrapped_f(*args):
     access_token = None
     try:
         access_token = json.loads(args[0].BODY)['access_token']
     except:
         try:
             access_token = args[0].POST['access_token']
         except:
             return HttpResponseForbidden
     try:
         o = OAuth.get(token=access_token)
     except:
         return HttpResponseForbidden
     if o.scope != realm:
         return HttpResponseForbidden
     f(*args)
def update_oauth(request):
    o = None
    created = False
    try:
        o = OAuth.get(username=request.user)
    except Process.DoesNotExist:
        o = OAuth(username=request.user,
                  consumer_key=request.FORM.consumer_key,
                  consumer_secret=request.FORM.consumer_secret,
                  scope=request.FORM.scope)
        created = True

    if not created and o is not None:
        o.consumer_key = request.FORM.consumer_key
        o.consumer_secret = request.FORM.consumer_secret
        o.realm = request.FORM.realm
    o.save()
def update_oauth(request):
    o = None
    created = False
    try:
        o = OAuth.get(username=request.user)
    except Process.DoesNotExist:
        o = OAuth(
            username=request.user,
            consumer_key=request.FORM.consumer_key,
            consumer_secret=request.FORM.consumer_secret,
            scope=request.FORM.scope
        )
        created = True

    if not created and o is not None:
        o.consumer_key = request.FORM.consumer_key
        o.consumer_secret = request.FORM.consumer_secret
        o.realm = request.FORM.realm
    o.save()