from common.logs import Log from oauth.auth import authenticator from util import response from common.config import Config log = Log() cnf = Config() def refresh_handler(event, context): refreshToken = event["body"]["refresh_token"] client_id = event["headers"]["client_id"] client_request_data = event["client_request_data"] return response.build( authenticator.refresh(refresh_token=refreshToken, client_id=client_id, client_request_data=client_request_data)) if __name__ == "__main__": event = { "refresh_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiIxMjM0NSIsImlzcyI6ImFiYy5jb20iLCJ0b2tlbl91c2UiOiJyZWZyZXNoIiwianRpIjoic2FqOUlybGpvcjF6ayIsImV4cCI6MTUwOTEzMTUwOCwiaWF0IjoxNTA2NTM5NTA4LCJzY29wZSI6eyJhY2Nlc3MiOnsiL2dyYW50IjpbIlBPU1QiXSwiL2V2ZW50IjpbIlBBVENIIiwiR0VUIl19LCJncmFudF9hY2Nlc3MiOlsidXBkYXRlLWV2ZW50IiwiZ3JhbnQtYWNjZXNzIiwiZ2V0LWV2ZW50Il19LCJyb2xsIjpbIkFETUlOIl0sInN1YiI6ImJpam95LnBhdWxAdG90aGVuZXcuY29tIn0.gupFbJtlWd50xu8aVm7rgrjeXMWH2Zz7LnIFxaJGiVU", "client_id": cnf.client_id, "client_request_data": { "todo": "TODO" } } log.info(refresh_handler(event, None))
"app_name": cnf.app_name, "request_id": cnf.request_id, "message": "An unknown error has occurred. Please try again." } return {"statusCode": statusCode, "body": str(errorObject)} try: return success_message_builder(authorizer.authorize(event)) except Exception as e: traceback.print_exc() return error_message_builder(e.message) if __name__== "__main__": headers = {"client_id": "12345"} body = "{\n \"authorizationToken\":\"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.9JSbvNmL3VmblhGdvRHQsVXYw5SevpWaiJiOiIWdzJCL91VfiM3clN2Yh1CduFmcnJiOiUWbh52Xu9Wa0NWYisHL9JCduVmdl1SZ0FGZwVnI6ISZtFmbf52bpR3YhJCLdJSYk5WZnFWL05WZ2VWLlRXYkBXdiwiI5NmblRXZw12bj1CduVmdl1SZ0FGZwVnIsIibvlGdhN2bs1CduVmdl1SZ0FGZwVnIsICdvx2ctQnblZXZtUGdhRGc1JyW6IyczV2YjF2XlNmc192clJ3X05WZ2VmI7xSfiQnblZXZtQXZnJiOiUWbh52Xu9Wa0NWYis3W6IyczV2YjF2X05WYydmIs0XX91lIhRmbldWYtQnblZXZtUGdhRGc1JCLik3YuVGdlBXbvNWL05WZ2VWLlRXYkBXdiwiIu9Wa0F2YvxWL05WZ2VWLlRXYkBXdiwiI09Gbz1CduVmdl1SZ0FGZwVnIbpjIzNXZjNWYfV2YyV3bzVmcfRnblZXZiwiIINEVBBlI6ICZvhGdl12XwRHdoJyes0nIUV0RiojIk9Ga0VWbfBHd0hmI7tlOiQnblZXZvICLd1nIUN1TQJiOiQ2boRXZt9Fc0RHais3W6ICduFmcn9iI7pjIzNXZjNWYisnOiUGcvN2ciwSOwADM3YjNwUTM6ICdhlmIskDM2MzN2YDM1EjOiAHelJCLdJiTJ1ERBJyW6ISZs9mciwiIzNXZjNWYiojIlNXdf5WZr9GdiwiIt92YuMmYhJiOiM3cpJCLiUDNzITMiojIkVXYiwiIVhkaUVDcQNjLaBVYzJiOikGdqJye.aYv4Fsv4qSUqOmSdD8SS_1awbdVf4cXm92G2n6uCeR8\"}" event = {"resource": "/validate", "path": "/validate", "httpMethod": "POST", "headers": headers, "queryStringParameters": None, "pathParameters": None, "stageVariables": None, "requestContext": {"path": "/login", "accountId": "187632318301", "resourceId": "gzmhx0", "stage": "test-invoke-stage", "requestId": "test-invoke-request", "identity": {"cognitoIdentityPoolId": None, "accountId": "187632318301", "cognitoIdentityId": None, "caller": "AIDAJHP6ODTX6ZTLMAC3I", "apiKey": "test-invoke-api-key", "sourceIp": "test-invoke-source-ip", "accessKey": "ASIAJPA6PQYVRHSTL7EA", "cognitoAuthenticationType": None, "cognitoAuthenticationProvider": None, "userArn": "arn:aws:iam::187632318301:user/geekcombat", "userAgent": "Apache-HttpClient/4.5.x (Java/1.8.0_131)", "user": "******"}, "resourcePath": "/login", "httpMethod": "POST", "apiId": "dhxwub3cn5"}, "body": body, "isBase64Encoded": False} log.info(validation_handler(event, None))