gpt4 book ai didi

azure - 使用 postman "url-missmatch"调用时,具有 B2C Auth 的 Entity Framework 重定向到空页面

转载 作者:行者123 更新时间:2023-12-03 02:00:06 28 4
gpt4 key购买 nike

当我尝试进行以下 API 调用时:

https://skillbasedmiddleware.azurewebsites.net/tables/useritem?$filter=(email eq '<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="5461611461617a3031" rel="noreferrer noopener nofollow">[email protected]</a>')

我被重定向到“登录”窗口,但随后保持空白。

当我尝试通过 postman (没有任何身份验证 token )向 URL 发出请求时,我得到:

<input type='hidden' name='error' id='error' value='redirect_uri_mismatch'/>
<input type='hidden' name='error_description' id='error_description' value='AADB2C90006: The redirect URI&#39;https://skillbasedmiddleware.azurewebsites.net/signin-oidc&#39; provided in the request is not registered for the client id &#39;XXX;. Correlation ID: 586439a6-0be6-45f1-aab2-b382dcb8f935' />

我的第一个问题:我被重定向并且窗口保持空白是否正确?
我的第二个问题:为什么会出现“URI MISSMATCH”?

这是我的 API 配置:

{
"AzureAdB2C": {
"Instance": "https://xxx.b2clogin.com",
"ClientId": "yyyy",
"Domain": "ccc.onmicrosoft.co",
"SignedOutCallbackPath": "/signout-oidc",
"SignUpSignInPolicyId": "B2C_1_Client"
},
"ConnectionStrings": {
"DefaultConnection": "Server=(localdb)\\mssqllocaldb;Database=NewDb;Trusted_Connection=True"
},
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}

这是我的 API 启动代码:

var builder = WebApplication.CreateBuilder(args);
var connectionString = builder.Configuration.GetConnectionString("DefaultConnection1");

if (connectionString == null)
{
throw new ApplicationException("DefaultConnection is not set");
}

builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddMicrosoftIdentityWebApp(builder.Configuration.GetSection("AzureADB2C"));

builder.Services.AddAuthorization(options =>
{
// By default, all incoming requests will be authorized according to
// the default policy
options.FallbackPolicy = options.DefaultPolicy;
});

builder.Services.AddDbContext<MigrationDbContext>(options => options.UseSqlServer(connectionString));
builder.Services.AddDatasyncControllers();

var app = builder.Build();

// Initialize the database
using (var scope = app.Services.CreateScope())
{
var context = scope.ServiceProvider.GetRequiredService<MigrationDbContext>();
//await context.InitializeDatabaseAsync().ConfigureAwait(false);
}

// Configure and run the web service.
app.UseAuthentication();
app.UseAuthorization();
app.MapControllers();
app.Run();

问题可能来自哪里?

最佳答案

如果您尝试创建 API,那么不,您被重定向到 B2C 是不对的,您应该收到 401 未经授权的响应。

看起来发生这种情况是因为您已将 API 配置为 a web app 进行身份验证(AddMicrosoftIdentityWebApp),而不是 a web API (AddMicrosoftIdentityWebApi)。

This link应该提供使用 B2C 进行设置的示例,但您需要:

  1. 在 B2C 中创建代表您的 MAUI 应用的应用注册(我认为您已经完成了此操作)
  2. 在 B2C 中创建代表您的 API 的应用注册
  3. 公开 API 应用注册中的权限,可用于限制 API 代码中的访问
  4. 向您的 MAUI 应用注册授予这些权限
  5. 配置您的 API 应用以对 API 调用进行身份验证。
  6. 当 MAUI 应用为您的用户请求 token 时,请将您的 API 应用注册作为附加范围包含在内(您应该被告知在第 3 步中公开权限时要使用什么值)
  7. 将您收到的 API 的 access_token 与您的所有 API 请求一起传递

关于azure - 使用 postman "url-missmatch"调用时,具有 B2C Auth 的 Entity Framework 重定向到空页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76564957/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com