Exemple #1
0
        private IActionResult RedirectToWalletPSBT(WalletId walletId, PSBT psbt, string fileName = null)
        {
            var vm = new PostRedirectViewModel()
            {
                AspController = "Wallets",
                AspAction     = nameof(WalletPSBT),
                Parameters    =
                {
                    new KeyValuePair <string, string>("psbt", psbt.ToBase64())
                }
            };

            if (!string.IsNullOrEmpty(fileName))
            {
                vm.Parameters.Add(new KeyValuePair <string, string>("fileName", fileName));
            }
            return(View("PostRedirect", vm));
        }
Exemple #2
0
        public async Task <IActionResult> AuthorizeAPIKey([FromForm] AuthorizeApiKeysViewModel viewModel)
        {
            await SetViewModelValues(viewModel);

            AdjustVMForAuthorization(viewModel);
            var ar = HandleCommands(viewModel);

            if (ar != null)
            {
                return(ar);
            }

            for (int i = 0; i < viewModel.PermissionValues.Count; i++)
            {
                if (viewModel.PermissionValues[i].Forbidden && viewModel.Strict)
                {
                    viewModel.PermissionValues[i].Value = false;
                    ModelState.AddModelError($"{viewModel.PermissionValues}[{i}].Value",
                                             $"The permission '{viewModel.PermissionValues[i].Title}' is required for this application.");
                }

                if (viewModel.PermissionValues[i].StoreMode == AddApiKeyViewModel.ApiKeyStoreMode.Specific &&
                    !viewModel.SelectiveStores)
                {
                    viewModel.PermissionValues[i].StoreMode = AddApiKeyViewModel.ApiKeyStoreMode.AllStores;
                    ModelState.AddModelError($"{viewModel.PermissionValues}[{i}].Value",
                                             $"The permission '{viewModel.PermissionValues[i].Title}' cannot be store specific for this application.");
                }
            }

            if (!ModelState.IsValid)
            {
                return(View(viewModel));
            }

            var command = viewModel.Command.ToLowerInvariant();

            switch (command)
            {
            case "cancel":
                return(RedirectToAction("APIKeys"));

            case "authorize":
            case "confirm":
                var key = command == "authorize"
                        ? await CreateKey(viewModel, (viewModel.ApplicationIdentifier, viewModel.RedirectUrl?.Authority))
                        : await _apiKeyRepository.GetKey(viewModel.ApiKey);

                if (viewModel.RedirectUrl != null)
                {
                    var permissions = key.GetBlob().Permissions;
                    var redirectVm  = new PostRedirectViewModel()
                    {
                        FormUrl    = viewModel.RedirectUrl.ToString(),
                        Parameters =
                        {
                            new KeyValuePair <string, string>("apiKey", key.Id),
                            new KeyValuePair <string, string>("userId", key.UserId)
                        }
                    };
                    foreach (var permission in permissions)
                    {
                        redirectVm.Parameters.Add(
                            new KeyValuePair <string, string>("permissions[]", permission));
                    }

                    return(View("PostRedirect", redirectVm));
                }

                TempData.SetStatusMessageModel(new StatusMessageModel()
                {
                    Severity = StatusMessageModel.StatusSeverity.Success,
                    Html     = $"API key generated! <code class='alert-link'>{key.Id}</code>"
                });

                return(RedirectToAction("APIKeys", new { key = key.Id }));

            default:
                return(View(viewModel));
            }
        }