exception is Exception of type 'Volo.Abp.Authorization.AbpAuthorizationException' was thrown. when I call await _partnerService.GetAsync(Guid.NewGuid());
i have tried like this but not work
private readonly IPartnersAppService _partnerService;
public ApiKeyMiddleware(RequestDelegate next, ILoggerFactory loggerFactory, IPartnersAppService partnerService)
{
_next = next;
_partnerService = partnerService;
_logger = loggerFactory.CreateLogger<ApiKeyMiddleware>();;
}
Hello,
I have added the ApiKeyMiddleware to filter the API and ensure that the request has the necessary API key to pass. In the InvokeAsync method, how can I inject the IPartnersAppService to retrieve the partner from the database for verification?
using System.IO;
using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
namespace AA.Core.BackOffice;
public class ApiKeyMiddleware
{
private readonly RequestDelegate _next;
private const string APIKEY = "key";
private readonly ILogger _logger;
public ApiKeyMiddleware(RequestDelegate next, ILoggerFactory loggerFactory)
{
_next = next;
_logger = loggerFactory.CreateLogger<ApiKeyMiddleware>();;
}
public async Task InvokeAsync(HttpContext context) {
await LogRequestBody(context);
if (!context.Request.Query.TryGetValue(APIKEY, out
var extractedApiKey)) {
context.Response.StatusCode = 401;
await context.Response.WriteAsync("Api Key was not provided ");
return;
}
var appSettings = context.RequestServices.GetRequiredService < IConfiguration > ();
var apiKey = appSettings.GetValue < string > ("App:AhamoveApiKey");
if (apiKey == null || !apiKey.Equals(extractedApiKey)) {
context.Response.StatusCode = 401;
await context.Response.WriteAsync("Unauthorized");
return;
}
await _next(context);
}
private async Task LogRequestBody(HttpContext context)
{
context.Request.EnableBuffering();
string requestBody = await new StreamReader(context.Request.Body, Encoding.UTF8).ReadToEndAsync();
context.Request.Body.Position = 0;
_logger.LogInformation("Request Body: {RequestBody}", requestBody);
}
}
ABP Framework version: v.7.3.2 UI Type: Angular Database System: MongoDB Tiered (for MVC) or Auth Server Separated (for Angular): yes Exception message and full stack trace: Steps to reproduce the issue:
yeah thank you :))
Hi,
I'm working on Vue.js and I want to send a request to log in. The flow is to send the username and password, and then return the token to access data. Does this flow already exist, or do I need to implement a new grant type for it? If it exists, please help me activate it.
ABP Framework version: v7.3.2 UI Type: Angular Database System: MongoDB Tiered (for MVC) or Auth Server Separated (for Angular): Yes Exception message and full stack trace: [Provide any relevant details] Steps to reproduce the issue:
hi,
The main reason from my custom role. If I use the admin role instead of my custom role, it works.
thanks Anjali Musmade
hi Anjali Musmade, have any idea to resolve this issue?
Hello,
I've added a new user through user migration with a user role, but I cannot log in to the app. When I remove the role, I can access the app. I'm not sure if I'm missing anything. Could you please help me with this?
I am using IdentityUser, UserManager, and RoleManager to create the user and role.
ABP Framework version: v7.3.2 UI Type: Angular Database System: MongoDB Tiered (for MVC) or Auth Server Separated (for Angular): Yes Exception message and full stack trace: [Provide any relevant details] Steps to reproduce the issue:
worked, thank you :))