标签: authorization

ASP.NET Core控制器注册授权包失败

如果我包含此包,我的 asp.net core 3.1 项目会引发异常(上下文:I\xe2\x80\x99m 尝试创建自定义授权策略):

\n
<PackageReference Include="Microsoft.AspNetCore.Authorization" Version="5.0.3" />\n
Run Code Online (Sandbox Code Playgroud)\n

这是在startup.cs中抛出的异常和方法:

\n
services.AddControllers();\n    System.ArgumentNullException: \'Value cannot be null. (Parameter \'configure\')\'\n
Run Code Online (Sandbox Code Playgroud)\n

这是完整的软件包列表。是否存在一些我不知道的冲突?当我创建一个类时,VS 建议使用该包AuthorizationHandler

\n
<PackageReference Include="Azure.Extensions.AspNetCore.Configuration.Secrets" Version="1.0.1" />\n<PackageReference Include="Azure.Identity" Version="1.2.3" />\n<PackageReference Include="Azure.Security.KeyVault.Secrets" Version="4.1.0" />\n<PackageReference Include="CorrelationId" Version="3.0.0" />\n<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.15.0" />\n<PackageReference Include="Microsoft.AspNetCore.Authentication.AzureAD.UI" Version="3.1.7" />\n<PackageReference Include="Microsoft.AspNetCore.Authorization" Version="5.0.3" />\n<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.1.9" />\n<PackageReference Include="Microsoft.AspNetCore.OData" Version="7.5.2" />\n<PackageReference Include="Microsoft.Identity.Web" Version="1.2.0" />\n<PackageReference Include="NSwag.AspNetCore" Version="13.8.2" />\n
Run Code Online (Sandbox Code Playgroud)\n

authorization asp.net-authorization asp.net-core

3
推荐指数
1
解决办法
1807
查看次数

如何通过控制器将参数传递给策略中使用的授权处理程序

我一直在寻找这个问题的答案,但似乎找不到直接的答案。我有一个在策略中使用的授权处理程序。典型示例如下:

services.AddAuthorization(options =>
    {
        options.AddPolicy("AtLeast21", policy =>
            policy.Requirements.Add(new MinimumAgeRequirement(21)));
    });
Run Code Online (Sandbox Code Playgroud)

然后在控制器上的授权属性中指定策略。我想做的是在控制器级别指定年龄要求。例如:

[Authorize(Policy = "AtLeast21", 21)]
Run Code Online (Sandbox Code Playgroud)

我的想法是,我可以将相同的授权处理程序用于多个控制器操作或多个策略。

有谁知道如何做到这一点?

policy authorization asp.net-core

3
推荐指数
1
解决办法
2608
查看次数

在asp.net core中成功登录后,非身份验证方法中的User.Identity.IsAuthenticated为false

我是 ASP.NET Core 的新手。我尝试使用不和谐作为第 3 方登录服务登录(例如使用 facebook、google 登录)。

我可以成功登录并拥有我的用户对象、声明,并且我可以输入具有授权属性的类。下面你可以看到 UserIdentity 没问题。

在此输入图像描述

但假设用户想要返回登录页面。在这种情况下,我必须将他重定向到索引,但我想通过使用 Identity 检查用户是否经过身份验证,不幸的是,它是错误的并且没有声明等。据我了解,它可能与 cookie 或其他东西有关相似的。我还对类使用不同的属性(不是授权而是允许匿名)你可以在我的 Identity 对象下面看到

在此输入图像描述

我正在分享我的验证码

services.AddAuthentication(options =>
{
    options.DefaultChallengeScheme = CookieAuthenticationDefaults.AuthenticationScheme;
    options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
    options.DefaultSignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
           
})
  .AddCookie(options =>
   {
      options.ExpireTimeSpan = TimeSpan.FromMinutes(30);
      options.Cookie.MaxAge = options.ExpireTimeSpan;
      options.SlidingExpiration = true;
      options.EventsType = typeof(CustomCookieAuthenticationEvents);
      options.AccessDeniedPath = "/auth/DiscordAuthFailed";

    })
     .AddJwtBearer(options =>
      {
        options.SaveToken = true;
        options.TokenValidationParameters = new TokenValidationParameters()
        {
           ValidateIssuer = false,
           ValidateAudience = false,
           ValidateIssuerSigningKey = true,
           ValidIssuer = Configuration.GetValue<string>("Jwt:Issuer"),
           ValidAudience = Configuration.GetValue<string>("Jwt:Audience"),
           IssuerSigningKey = new …
Run Code Online (Sandbox Code Playgroud)

c# authorization oauth asp.net-core discord

3
推荐指数
1
解决办法
7443
查看次数

.NET 6应用程序注册授权验证令牌但返回401-未经授权错误

我正在尝试为 ASP.NET Core 6 Web API 进行应用程序注册授权。我使用应用程序注册凭据获取令牌并通过 API 进行身份验证。令牌验证似乎有效,但我收到 401-未经授权的错误,没有任何信息。在 Postman 中显示为无效令牌。

这是我获取令牌的客户端设置

var keyValues = new List<KeyValuePair<string, string>>
                {
                    new KeyValuePair<string, string>("tenant_id", tenant_id),
                    new KeyValuePair<string, string>("client_id", client_id),
                    new KeyValuePair<string, string>("client_secret", client_secret),
                    new KeyValuePair<string, string>("scope", scope),
                    new KeyValuePair<string, string>("grant_type", "client_credentials")
                };

var c = new FormUrlEncodedContent(keyValues);
tokenUrl = "https://login.microsoftonline.com/"+tenant_id+"/oauth2/v2.0";

var call = await client.PostAsync(tokenUrl + "/token", c);}
Run Code Online (Sandbox Code Playgroud)

Web APIappsettings.json设置与令牌参数匹配

{
    "AzureAd": {
        "Instance": "https://login.microsoftonline.com",
        "Domain": "<domain>",
        "TenantId": "<tenant>",
        "ClientId": "<clientId>",
        "ClientSecret": "<clientSecret>",
        "Roles": "api://<role>"
      },
}
Run Code Online (Sandbox Code Playgroud)

API 正在使用新的调用从 …

c# authorization azure-app-registration

3
推荐指数
1
解决办法
1212
查看次数

Supabase Auth UI:显示注册 UI 而不是登录 UI?

我使用 Supabase Auth UI 作为我网站的登录/注册身份验证提供商。

目前,Auth UI 始终显示登录按钮。我可以通过点击“没有帐户?注册”成功进入注册界面。所有登录和注册在技术上都是有效的,但我希望能够显示注册页面(例如我的注册按钮),以便用户不会认为他们正在注册,并且在注册时必须重新填写详细信息他们意识到自己正在尝试登录。

让我控制 UI 显示的哪一部分似乎是理所当然的,但我找不到办法做到这一点?

import React from "react";
import { Auth } from "@supabase/auth-ui-react";
import { ThemeSupa } from "@supabase/auth-ui-shared";
import { useNavigate } from "react-router-dom";
import IconLogo from "../../img/brand/icononly_nobuffer.png";
import { Link } from "react-router-dom";
import { supabase } from "../../utils/supabase";

export default function Register() {
  const navigate = useNavigate();

  supabase.auth.onAuthStateChange(async (event, session) => {
    console.log("Auth state changed:", event);
    if (event === "SIGNED_IN" || event === "USER_UPDATED") {
      const { data, error …
Run Code Online (Sandbox Code Playgroud)

javascript authentication authorization supabase

3
推荐指数
1
解决办法
369
查看次数

使用IIS和MVC进行授权的问题

设置授权时出现问题.首先我得到:

<authorization>
  <deny users="?" />
</authorization>
Run Code Online (Sandbox Code Playgroud)

所以我拒绝所有未知用户,然后允许他们查看这些页面:

<location path="Default.aspx">
  <system.web>
    <authorization>
      <allow users="*" />
    </authorization>
  </system.web>
</location>

<location path="Public">
  <system.web>
    <authorization>
      <allow users="*" />
    </authorization>
  </system.web>
</location>
Run Code Online (Sandbox Code Playgroud)

现在问题..他们可以访问公共页面和Default.aspx ..但不能访问www.mydomain.com或www.mydomain.com/ ..所以www.mydmain.com/Default.aspx工作正常.那么如何让这些工作呢?

iis asp.net-mvc iis-7 authorization

2
推荐指数
1
解决办法
5347
查看次数

签署API请求时要包含的内容

如果我有一个作为API请求发送的复杂对象(例如下面的Order),我应该在生成签名时包含所有属性还是仅使用一个子集?

我问,因为我不清楚,从查看其他API的请求参数是扁平和简单的

public class Order
    {
        public string Id { get; set; }
        public string ClientIdentifier { get; set; }
        public IEnumerable<OrderItems> OrderItems { get; set; }
        public long timestamp { get; set; }
        public string signature { get; set; }
    }

public class OrderItems
{
    public string ItemId { get; set; }
    public string Name { get; set; }
    public IEnumerable<decimal> PriceBands { get; set; }pes
            more types



}

and so on ....
Run Code Online (Sandbox Code Playgroud)

c# authorization oauth

2
推荐指数
1
解决办法
2335
查看次数

如何在背景图片上设置授权标头:url()?

我正在尝试通过REST API检索背景图像。

但是,这样做,我需要授权。

该令牌可从应该加载背景图像的上下文中获得,但是我不知道如何将其添加到请求中。

有任何想法吗?这有可能吗?

在另一种方法中,我使用Web服务器将授权添加到特定上下文中的所有请求。这工作正常,但不可能了。

javascript authorization http reactjs

2
推荐指数
1
解决办法
2168
查看次数

Laravel指数政策

我使用Laravel 5.4,我正在尝试为索引视图编写策略.我试图使用没有模型方法,我收到以下错误:

Handler.php第133行中的HttpException:

此操作未经授权.

这是我的控制器:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\County;
use Session;
use App\Http\Controllers\Controller;

class CountyController extends Controller
{
    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('auth');
    }

    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        $counties = County::orderBy('id', 'desc')->paginate(5);
        $this->authorize('index');

        return view('county.index', array(
                'counties' => $counties
            ));
    }
Run Code Online (Sandbox Code Playgroud)

这是我的AuthServicePovider:

<?php

namespace App\Providers;

use Illuminate\Support\Facades\Gate;
use …
Run Code Online (Sandbox Code Playgroud)

php authorization laravel-5.4

2
推荐指数
1
解决办法
3293
查看次数

是否可以从WebAPI 2中的authToken(RequestContext)访问clientId

我已经使用我的WebAPI 2应用程序实现了Oauth,并且有几个应用程序访问API.经过身份验证后,在通过身份验证令牌发送请求后,我可以按如下方式访问用户:

var currentUser = RequestContext.Principal;
Run Code Online (Sandbox Code Playgroud)

登录时,clientId设置如下:

context.OwinContext.Set<AppClient>("oauth:client", client);
Run Code Online (Sandbox Code Playgroud)

有没有办法访问该客户端ID?我想限制某些客户端的某些操作/控制器.有没有办法做到这一点?

我试过让客户端如下:

var client = Request.GetOwinContext().Get<string>("oauth:client");
Run Code Online (Sandbox Code Playgroud)

但这不起作用.

c# authorization oauth-2.0 owin asp.net-web-api2

2
推荐指数
1
解决办法
1264
查看次数