/** * Refresh access token. */ public async Task <APIGatewayProxyResponse> RefreshAccessToken(IDataStores dataStores, IDictionary <string, string> requestHeaders, JObject requestBody) { Debug.Untested(); Debug.AssertValid(dataStores); Debug.AssertValid(requestHeaders); Debug.AssertValid(requestBody); try { // Log call LoggingHelper.LogMessage($"UserIdentityService::RefreshAccessToken()"); // Get the NoSQL DB client AmazonDynamoDBClient dbClient = (AmazonDynamoDBClient)dataStores.GetNoSQLDataStore().GetDBClient(); Debug.AssertValid(dbClient); // Check inputs APIHelper.CheckEmptyRequestBody(requestBody); // Check authenticated endpoint security string loggedInUserId = await APIHelper.CheckLoggedIn(dbClient, requestHeaders); Debug.AssertID(loggedInUserId); // Perform logic DateTime?expiryTime = await UserIdentityService_RefreshAccessToken_LogicLayer.RefreshAccessToken(dbClient, loggedInUserId); Debug.AssertValid(expiryTime); // Respond RefreshAccessTokenResponse response = new RefreshAccessTokenResponse { expiryTime = APIHelper.APIDateTimeStringFromDateTime(expiryTime) }; return(new APIGatewayProxyResponse { StatusCode = APIHelper.STATUS_CODE_OK, Body = JsonConvert.SerializeObject(response) }); //??--return Ok(response); } catch (Exception exception) { Debug.Tested(); if (exception.Message == IdentityServiceLogicLayer.ERROR_CANNOT_EXTEND_ACCESS_TOKEN) { Debug.Untested(); return(new APIGatewayProxyResponse { StatusCode = APIHelper.STATUS_CODE_FORBIDDEN, Body = $"{{ error = {IdentityServiceLogicLayer.CANNOT_EXTEND_ACCESS_TOKEN} }}" }); //??--return StatusCode(APIHelper.STATUS_CODE_FORBIDDEN, new GeneralErrorResponse { error = IdentityServiceLogicLayer.CANNOT_EXTEND_ACCESS_TOKEN }); } else { Debug.Tested(); return(APIHelper.ResponseFromException(exception)); } } }
/** * Set user address. */ private async Task <APIGatewayProxyResponse> VerifyPhoneNumber(IDataStores dataStores, IDictionary <string, string> requestHeaders, JObject requestBody) { Debug.Untested(); Debug.AssertValid(dataStores); Debug.AssertValid(requestHeaders); Debug.AssertValidOrNull(requestBody); try { // Log call LoggingHelper.LogMessage($"UserIdentityService::VerifyPhoneNumber()"); // Get the NoSQL DB client AmazonDynamoDBClient dbClient = (AmazonDynamoDBClient)dataStores.GetNoSQLDataStore().GetDBClient(); Debug.AssertValid(dbClient); // Check inputs VerifyPhoneNumberRequest verifyPhoneNumberRequest = UserIdentityService_VerifyPhoneNumber_LogicLayer.CheckValidVerifyPhoneNumberRequest(requestBody); Debug.AssertValid(verifyPhoneNumberRequest); // Check authenticated endpoint security string loggedInUserId = await APIHelper.CheckLoggedIn(dbClient, requestHeaders); Debug.AssertID(loggedInUserId); // Perform logic await UserIdentityService_VerifyPhoneNumber_LogicLayer.VerifyPhoneNumber(dbClient, loggedInUserId, verifyPhoneNumberRequest); // Respond return(new APIGatewayProxyResponse { StatusCode = APIHelper.STATUS_CODE_NO_CONTENT }); } catch (Exception exception) { Debug.Tested(); if (exception.Message == IdentityServiceLogicLayer.ERROR_INCORRECT_PASSWORD) { Debug.Untested(); //??-- ObjectResult result = new ObjectResult(new GeneralErrorResponse { error = IdentityServiceLogicLayer.INCORRECT_PASSWORD }); // result.StatusCode = APIHelper.STATUS_CODE_UNAUTHORIZED; // return result; return(new APIGatewayProxyResponse { StatusCode = APIHelper.STATUS_CODE_UNAUTHORIZED, Body = $"{{ error = \"{IdentityServiceLogicLayer.INCORRECT_PASSWORD}\" }}" }); } else { Debug.Tested(); return(APIHelper.ResponseFromException(exception)); } } }
/** * Set user password. */ internal async Task <APIGatewayProxyResponse> SetUserPassword(IDataStores dataStores, IDictionary <string, string> requestHeaders, JObject requestBody) { Debug.Untested(); Debug.AssertValid(dataStores); Debug.AssertValid(requestHeaders); Debug.AssertValidOrNull(requestBody); try { // Log call LoggingHelper.LogMessage($"UserIdentityService::SetUserPassword()"); // Get the NoSQL DB client AmazonDynamoDBClient dbClient = (AmazonDynamoDBClient)dataStores.GetNoSQLDataStore().GetDBClient(); Debug.AssertValid(dbClient); // Check inputs SetUserPasswordRequest setUserPasswordRequest = UserIdentityService_SetUserPassword_LogicLayer.CheckValidSetUserPasswordRequest(requestBody); Debug.AssertValid(setUserPasswordRequest); // Check authenticated endpoint security string loggedInUserId = await APIHelper.CheckLoggedIn(dbClient, requestHeaders); Debug.AssertID(loggedInUserId); // Perform logic await UserIdentityService_SetUserPassword_LogicLayer.SetUserPassword(dbClient, loggedInUserId, setUserPasswordRequest); // Respond return(new APIGatewayProxyResponse { StatusCode = APIHelper.STATUS_CODE_NO_CONTENT }); } catch (Exception exception) { Debug.Tested(); if (exception.Message == IdentityServiceLogicLayer.ERROR_INCORRECT_PASSWORD) { Debug.Untested(); return(new APIGatewayProxyResponse { StatusCode = APIHelper.STATUS_CODE_UNAUTHORIZED, Body = $"{{ body = \"{IdentityServiceLogicLayer.INCORRECT_PASSWORD}\"}}" }); } else { Debug.Tested(); return(APIHelper.ResponseFromException(exception)); } } }
/** * Get user permissions. */ public async Task <APIGatewayProxyResponse> GetUserPermissions(IDataStores dataStores, IDictionary <string, string> requestHeaders) { Debug.Untested(); Debug.AssertValid(dataStores); Debug.AssertValid(requestHeaders); try { // Log call LoggingHelper.LogMessage($"UserIdentityService::GetUserPermissions()"); // Get the NoSQL DB client AmazonDynamoDBClient dbClient = (AmazonDynamoDBClient)dataStores.GetNoSQLDataStore().GetDBClient(); Debug.AssertValid(dbClient); // Check authenticated endpoint security string loggedInUserId = await APIHelper.CheckLoggedIn(dbClient, requestHeaders); Debug.AssertID(loggedInUserId); // Perform logic var permissions = await UserIdentityService_GetUserPermissions_LogicLayer.GetUserPermissions(dbClient, loggedInUserId); Debug.AssertValid(permissions); GetPermissionsResponse response = new GetPermissionsResponse(); response.permissions = permissions; //??--GetPermissionsResponse response = await UserIdentityService_GetUserPermissions_LogicLayer.GetUserPermissions(dbClient, loggedInUserId); //Debug.AssertValid(response); // Respond return(new APIGatewayProxyResponse { StatusCode = APIHelper.STATUS_CODE_OK, Body = JsonConvert.SerializeObject(response) }); } catch (Exception exception) { Debug.Tested(); return(APIHelper.ResponseFromException(exception)); } }
/** * Set user allow non-essential emails. */ private async Task <APIGatewayProxyResponse> SetUserAllowNonEssentialEmails(IDataStores dataStores, IDictionary <string, string> requestHeaders, JObject requestBody) { Debug.Untested(); Debug.AssertValid(dataStores); Debug.AssertValid(requestHeaders); Debug.AssertValidOrNull(requestBody); try { // Log call LoggingHelper.LogMessage($"UserIdentityService::SetUserAllowNonEssentialEmails()"); // Get the NoSQL DB client AmazonDynamoDBClient dbClient = (AmazonDynamoDBClient)dataStores.GetNoSQLDataStore().GetDBClient(); Debug.AssertValid(dbClient); // Check inputs SetUserAllowNonEssentialEmailsRequest setUserAllowNonEssentialEmailsRequest = UserIdentityService_SetUserAllowNonEssentialEmails_LogicLayer.CheckValidSetUserAllowNonEssentialEmailsRequest(requestBody); Debug.AssertValid(setUserAllowNonEssentialEmailsRequest); // Check authenticated endpoint security string loggedInUserId = await APIHelper.CheckLoggedIn(dbClient, requestHeaders); Debug.AssertID(loggedInUserId); // Perform logic await UserIdentityService_SetUserAllowNonEssentialEmails_LogicLayer.SetUserAllowNonEssentialEmails(dbClient, loggedInUserId, setUserAllowNonEssentialEmailsRequest); // Respond return(new APIGatewayProxyResponse { StatusCode = APIHelper.STATUS_CODE_NO_CONTENT }); } catch (Exception exception) { Debug.Tested(); return(APIHelper.ResponseFromException(exception)); } }
/** * Set user email. */ internal async Task <APIGatewayProxyResponse> SetUserEmail(IDataStores dataStores, IDictionary <string, string> requestHeaders, JObject requestBody) { Debug.Untested(); Debug.AssertValid(dataStores); Debug.AssertValid(requestHeaders); Debug.AssertValidOrNull(requestBody); try { // Log call LoggingHelper.LogMessage($"UserIdentityService::SetUserEmail()"); // Get the NoSQL DB client AmazonDynamoDBClient dbClient = (AmazonDynamoDBClient)dataStores.GetNoSQLDataStore().GetDBClient(); Debug.AssertValid(dbClient); // Check inputs SetUserEmailRequest setUserEmailRequest = UserIdentityService_SetUserEmail_LogicLayer.CheckValidSetUserEmailRequest(requestBody); Debug.AssertValid(setUserEmailRequest); // Check authenticated endpoint security string loggedInUserId = await APIHelper.CheckLoggedIn(dbClient, requestHeaders); Debug.AssertID(loggedInUserId); // Perform logic await UserIdentityService_SetUserEmail_LogicLayer.SetUserEmail(dbClient, loggedInUserId, setUserEmailRequest); // Respond return(new APIGatewayProxyResponse { StatusCode = APIHelper.STATUS_CODE_NO_CONTENT }); } catch (Exception exception) { Debug.Tested(); if ((exception.Message == IdentityServiceLogicLayer.ERROR_EMAIL_IN_USE) || (exception.Message == IdentityServiceLogicLayer.ERROR_EMAIL_ALREADY_BEING_CHANGED)) { Debug.Untested(); GeneralErrorResponse response = new GeneralErrorResponse(); if (exception.Message == IdentityServiceLogicLayer.ERROR_EMAIL_IN_USE) { Debug.Untested(); response.error = IdentityServiceLogicLayer.EMAIL_IN_USE; } else if (exception.Message == IdentityServiceLogicLayer.ERROR_EMAIL_ALREADY_BEING_CHANGED) { Debug.Untested(); response.error = IdentityServiceLogicLayer.EMAIL_ALREADY_BEING_CHANGED; } //??--ObjectResult result = new ObjectResult(response); //??--result.StatusCode = APIHelper.STATUS_CODE_UNAUTHORIZED; //??--return StatusCode(APIHelper.STATUS_CODE_UNAUTHORIZED, response); return(new APIGatewayProxyResponse { StatusCode = APIHelper.STATUS_CODE_UNAUTHORIZED, Body = JsonConvert.SerializeObject(response) }); } else { Debug.Tested(); return(APIHelper.ResponseFromException(exception)); } } }
/** * Check password. */ public async Task <APIGatewayProxyResponse> CheckPassword(IDataStores dataStores, IDictionary <string, string> requestHeaders, JObject requestBody) { Debug.Untested(); Debug.AssertValid(dataStores); Debug.AssertValid(requestHeaders); Debug.AssertValid(requestBody); try { // Log call LoggingHelper.LogMessage($"UserIdentityService::CheckPassword()"); // Get the NoSQL DB client AmazonDynamoDBClient dbClient = (AmazonDynamoDBClient)dataStores.GetNoSQLDataStore().GetDBClient(); Debug.AssertValid(dbClient); // Check inputs CheckPasswordRequest checkPasswordRequest = UserIdentityService_CheckPassword_LogicLayer.CheckValidCheckPasswordRequest(requestBody); Debug.AssertValid(checkPasswordRequest); // Check authenticated endpoint security string loggedInUserId = await APIHelper.CheckLoggedIn(dbClient, requestHeaders); Debug.AssertID(loggedInUserId); // Perform logic await UserIdentityService_CheckPassword_LogicLayer.CheckPassword(dbClient, checkPasswordRequest, loggedInUserId); // Respond return(new APIGatewayProxyResponse { StatusCode = APIHelper.STATUS_CODE_OK }); } catch (Exception exception) { Debug.Tested(); if ((exception.Message == IdentityServiceLogicLayer.ERROR_INCORRECT_PASSWORD) || (exception.Message == IdentityServiceLogicLayer.ERROR_USER_BLOCKED) || (exception.Message == IdentityServiceLogicLayer.ERROR_USER_LOCKED)) { Debug.Untested(); //??--GeneralErrorResponse response = new GeneralErrorResponse(); string error = null; if (exception.Message == IdentityServiceLogicLayer.ERROR_INCORRECT_PASSWORD) { Debug.Tested(); error = IdentityServiceLogicLayer.INCORRECT_PASSWORD; } else if (exception.Message == IdentityServiceLogicLayer.ERROR_USER_BLOCKED) { Debug.Tested(); error = IdentityServiceLogicLayer.USER_BLOCKED; } else if (exception.Message == IdentityServiceLogicLayer.ERROR_USER_LOCKED) { Debug.Tested(); error = IdentityServiceLogicLayer.USER_LOCKED; } //??-- ObjectResult result = new ObjectResult(response); // result.StatusCode = APIHelper.STATUS_CODE_UNAUTHORIZED; // return result; return(new APIGatewayProxyResponse { StatusCode = APIHelper.STATUS_CODE_UNAUTHORIZED, Body = $"{{ error = \"{error}\"}}" }); } else { Debug.Tested(); return(APIHelper.ResponseFromException(exception)); } } }