def token(token_req): """ handler to convert a code into an authorization token token_req provided by validate_token_request decorator once neuaer recieves the code provided in the authorize method it will contact the app here where the code can be 'redeemed' for an authorization token """ # get the stored authorization using the code and request uri auth = Authorization.get_with_auth(code=token_req.raw_args.get('code'), uri=token_req.raw_args.get('redirect_uri')) # if there were no matches report if not auth: return jsonify(**token_error_responses('no_match')) # if the access token has already been granted for this uri and code if auth.access_token: return jsonify(**token_error_responses('already_granted')) # return the access token to the requester return jsonify(access_token=auth.generate_token())