Exemple #1
0
        /**
         * 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));
                }
            }
        }
Exemple #2
0
        /**
         * Logout.
         */
        public async Task <APIGatewayProxyResponse> Logout(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::Logout()");

                // 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
                await UserIdentityService_Logout_LogicLayer.Logout(dbClient, loggedInUserId);

                // Respond
                return(new APIGatewayProxyResponse {
                    StatusCode = APIHelper.STATUS_CODE_NO_CONTENT
                });
            } catch (Exception exception) {
                Debug.Tested();
                return(APIHelper.ResponseFromException(exception));
            }
        }