

@app.route('/success', methods=['GET'])
def handleLoginSuccess():
    app.logger.info(('handleLoginSuccess [%s]' % request.method))
    me = request.args.get('me')
    code = request.args.get('code')
    app.logger.info(('me [%s] code [%s]' % (me, code)))
    if (db is not None):
        app.logger.info('getting data to validate auth code')
        key = ('login-%s' % me)
        data = db.hgetall(key)
        if data:
            r = ninka.indieauth.validateAuthCode(code=code, client_id=me, redirect_uri=data['redirect_uri'])
            if (r['status'] == requests.codes.ok):
                app.logger.info('login code verified')
                scope = r['response']['scope']
                from_uri = data['from_uri']
                token = str(uuid.uuid4())
                db.hset(key, 'code', code)
                db.hset(key, 'token', token)
                db.expire(key, cfg['auth_timeout'])
                db.set(('token-%s' % token), key)
                db.expire(('token-%s' % code), cfg['auth_timeout'])
                session['indieauth_token'] = token
                session['indieauth_scope'] = scope
                session['indieauth_id'] = me
            else:
                app.logger.info('login invalid')
                clearAuth()
        else:
            app.logger.info(('nothing found for [%s]' % me))
    if scope:
        if from_uri:
            return redirect(from_uri)
        else:
            return redirect('/')
    else:
        return ('authentication failed', 403)

dataset/ETHPy150Open bear/python-indieweb/indieweb.py handleLoginSuccess/original