def auth():
    s = request.environ.get('beaker.session')
    
    o = lib.get_oauth_handler(conf.site_url+'/authd')
    url = o.get_authorization_url()
    
    s['request_token'] = o.request_token
    s.save()
    
    raise HTTPResponse("", status=303, header=dict(Location=url))
def authd():
    s = request.environ.get('beaker.session')
    request_token = s.get('request_token', '')
    if not request_token:
        abort(403, 'request token not set') 
    
    token = request.GET.get('oauth_token')
    verifier = request.GET.get('oauth_verifier')
    
    o = lib.get_oauth_handler()
    o.set_request_token(request_token.key, request_token.secret)
    try:
        access_token = o.get_access_token(verifier)
    except Exception, e:
        abort(500, 'check access_token failed')