authorization 相关问题

授权是确定是否允许用户,程序或设备以特定方式访问受保护资源的过程。授权是计算机安全实践的关键主题。

如何使授权服务器与外部数据库保持同步?

我当前的系统如下所示: 包含用户信息(ID、用户名、电子邮件)的授权服务器(AWS Cognito 用户池) MySQL 数据库包含非身份验证相关的用户信息(例如朋友连接...

回答 1 投票 0

如何处理 OAuth 中多个选项卡设置的令牌

我正在构建一个新的身份验证服务,并希望使用一次性刷新令牌。 理论上它工作得很好,但是我如何处理多个选项卡之间的共享令牌而不遇到竞争条件

回答 1 投票 0

Blazor 登录页面 jwt 不记名令牌和授权

@页面“/登录” @使用System.Net.Http @使用System.Net.Http.Json @使用System.Text.Json @inject IHttpClientFactory HttpClientFactory @inject IJSRuntime JSRuntime 登录 @page "/login" @using System.Net.Http @using System.Net.Http.Json @using System.Text.Json @inject IHttpClientFactory HttpClientFactory @inject IJSRuntime JSRuntime <h3>Login</h3> @if (!string.IsNullOrWhiteSpace(errorMessage)) { <div class="alert alert-danger">@errorMessage</div> } <div class="form-group"> <label for="email">Email:</label> <input type="email" class="form-control" id="email" @bind="email" /> </div> <div class="form-group"> <label for="password">Password:</label> <input type="password" class="form-control" id="password" @bind="password" /> </div> <button class="btn btn-primary" @onclick="Login">Login</button> @code { private string email; private string password; private string errorMessage; private async Task Login() { try { var httpClient = HttpClientFactory.CreateClient(); // Create a JSON object to send to the API var loginData = new { Email = email, Password = password }; // Serialize the object to JSON var jsonContent = new StringContent(JsonSerializer.Serialize(loginData), Encoding.UTF8, "application/json"); // Send a POST request to your authentication API to get a JWT token var response = await httpClient.PostAsJsonAsync("https://your-auth-api.com/login", loginData); // Check if the request was successful if (response.IsSuccessStatusCode) { // Deserialize the response to get the JWT token var token = await response.Content.ReadAsStringAsync(); // Store the token securely (e.g., in local storage or a secure cookie) // For demonstration, we'll just set it in a session variable await JSRuntime.InvokeVoidAsync("sessionStorage.setItem", "jwtToken", token); // Redirect to the secured page NavigationManager.NavigateTo("/secure"); } else { errorMessage = "Invalid email or password."; } } catch (Exception ex) { errorMessage = "An error occurred: " + ex.Message; } } } 我正在尝试向 api 发送登录信息,并获取一个在每个页面中使用的令牌,以便再次发送到 api,但我是 blazor 的新手,所以我如何使用 jwt 持有者获取令牌并将其发送到其他页面, 另外,如果有人检查我的代码并给我反馈(无论其真实与否),我都会很高兴。非常感谢 您需要开始的所有内容都在这个存储库中。这是我的第一次介绍,它让我很快就开始了。 https://github.com/cornflourblue/blazor-web assembly-jwt-authentication-example 文档和演示在此页面中。 https://jasonwatmore.com/post/2020/08/13/blazor-web assembly-jwt-authentication-example-tutorial 从存储库检查此类 “AuthenticationService.cs”。 using BlazorApp.Models; using Microsoft.AspNetCore.Components; using System.Threading.Tasks; namespace BlazorApp.Services { public interface IAuthenticationService { User User { get; } Task Initialize(); Task Login(string username, string password); Task Logout(); } public class AuthenticationService : IAuthenticationService { private IHttpService _httpService; private NavigationManager _navigationManager; private ILocalStorageService _localStorageService; public User User { get; private set; } public AuthenticationService( IHttpService httpService, NavigationManager navigationManager, ILocalStorageService localStorageService ) { _httpService = httpService; _navigationManager = navigationManager; _localStorageService = localStorageService; } public async Task Initialize() { User = await _localStorageService.GetItem<User>("user"); } public async Task Login(string username, string password) { User = await _httpService.Post<User>("/users/authenticate", new { username, password }); await _localStorageService.SetItem("user", User); } public async Task Logout() { User = null; await _localStorageService.RemoveItem("user"); _navigationManager.NavigateTo("login"); } } } 然后,一旦您登录,您就可以通过这种方式调用您的后端。 namespace BlazorApp.Services { public interface IHttpService { Task<T> Get<T>(string uri); Task<T> Post<T>(string uri, object value); } public class HttpService : IHttpService { private HttpClient _httpClient; private NavigationManager _navigationManager; private ILocalStorageService _localStorageService; private IConfiguration _configuration; public HttpService( HttpClient httpClient, NavigationManager navigationManager, ILocalStorageService localStorageService, IConfiguration configuration ) { _httpClient = httpClient; _navigationManager = navigationManager; _localStorageService = localStorageService; _configuration = configuration; } public async Task<T> Get<T>(string uri) { var request = new HttpRequestMessage(HttpMethod.Get, uri); return await sendRequest<T>(request); } public async Task<T> Post<T>(string uri, object value) { var request = new HttpRequestMessage(HttpMethod.Post, uri); request.Content = new StringContent(JsonSerializer.Serialize(value), Encoding.UTF8, "application/json"); return await sendRequest<T>(request); } // helper methods private async Task<T> sendRequest<T>(HttpRequestMessage request) { // add jwt auth header if user is logged in and request is to the api url var user = await _localStorageService.GetItem<User>("user"); var isApiUrl = !request.RequestUri.IsAbsoluteUri; if (user != null && isApiUrl) request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", user.Token); using var response = await _httpClient.SendAsync(request); // auto logout on 401 response if (response.StatusCode == HttpStatusCode.Unauthorized) { _navigationManager.NavigateTo("logout"); return default; } // throw exception on error response if (!response.IsSuccessStatusCode) { var error = await response.Content.ReadFromJsonAsync<Dictionary<string, string>>(); throw new Exception(error["message"]); } return await response.Content.ReadFromJsonAsync<T>(); } } } 祝一切顺利,继续编码。

回答 1 投票 0

动态更改用户声明/身份验证状态 blazor 服务器

我正在开发一个应用程序,允许管理员类型用户更改普通用户的访问权限。 我正在使用 blazor 服务器和 mudblazor。我目前已将其设置为管理员可以单击...

回答 1 投票 0

需要根据不同PiP进行评估的XACML策略

我是 xacml 的新手,我试图了解 PDP 在实践中如何评估依赖于多个 PIP 的策略。让我们举个例子: 想象一下乔希可以扮演......的角色的情况

回答 1 投票 0

您是否应该将授权标头发送到不受限制的端点 REST?

我有一个带有 JWT 身份验证的 Rest API(在 Spring Boot 中编码)。一切正常,但是如果您将无效的 JWT 发送到不受限制的端点,我会收到 401 未经授权的响应。如果我没有发送 JWT

回答 1 投票 0

Laravel 策略授权的自定义消息

在我的 Laravel 5.8 项目中,我正在实现一个类似于 Stack Exchange 的信誉系统:例如,用户只有拥有“3 级”信誉才能回复讨论。 我想要...

回答 4 投票 0

使用oauth授权码流程获取访问令牌,无需设置Web服务器

我需要开发一个控制台应用程序来调用受 oauth2 协议保护的 API。 我不想开发一个 Web 服务器来捕获授权代码回调,因为这是一个 on

回答 1 投票 0

NextJS 中的授权代码流程 - 如何将 PKCE code_verifier 传递给授权回调?

我已经使用 openid-client 在 NextJS 中实现了 OAuth2 授权代码流程(尚未使用 PKCE)。现在我应该在哪里存储 code_verifier 以及如何将其传递给调用的回调

回答 1 投票 0

多个 HTTP 授权标头?

是否可以在 HTTP 消息中包含多个授权标头?具体来说,我想包括一种承载令牌类型(传递 OAuth 访问令牌)和一种基本类型(pa...

回答 7 投票 0

.NET微服务授权

我即将启动一个由多个微服务组成的项目,我正在研究如何实现每个微服务的授权。 我的架构如下: 一个网络项目

回答 3 投票 0

ApiException:10:开发者控制台设置不正确

我对这个问题越来越感到沮丧。 场景:我使用 Firebase 为我的应用程序设置 Google 身份验证。 我已将所有 3 个 Sha1 键添加到我的 Firebase 项目设置中(调试、发布...

回答 1 投票 0

Keyclock springboot 对于未经身份验证的请求返回 403 而不是 401

启用策略强制执行器配置时,对于未经身份验证的请求,Keyclock 返回 403 而不是 401。删除策略强制执行器配置时,它会返回 401。 使用此配置我得到一个 403 空回复...

回答 4 投票 0

Spring JWT 身份验证,“.hasAuthority()”返回“范围不足”错误

我现在正在使用 JWT 作为 Spring 的身份验证。我还使用具有自定义权限的自定义 AppUser 实体。 以下是这些实体的代码: 应用程序用户实体 @实体 @Table(name="app_...

回答 1 投票 0

使用 Socket.IO 进行授权和握手

我想知道Socket.IO中授权和握手的主要功能是什么。我已经阅读了他们在 GitHub 上的 wiki 和授权指南,但我仍然不明白以下内容: 嗬...

回答 6 投票 0

有没有办法使用 Google Cloud IAM 在我的网络应用程序上进行授权访问?

我正在寻找一种方法来限制在我的网络应用程序上的使用,方法是要求用户登录并根据某些列表的成员身份授予访问权限。 该功能就像与每个人共享 Google 文档一样...

回答 1 投票 0

在 AWS 中的自定义授权者中允许访客模式(无授权)

我正在尝试找到一种方法来允许AWS中的自定义授权者使用访客模式。 基本上,我想要实现的是以下场景: 如果请求中没有 Authorization 标头,则触发 l...

回答 3 投票 0

基于最小API身份验证获取数据

我正在使用本教程为我的最小 API (.Net 7) 设置身份验证和授权:https://www.telerik.com/blogs/authorization-authentication-minimal-apis 我从来没有做过这个...

回答 1 投票 0

useSession() 钩子在 NextJS v13.4.3 中返回未定义

我是 NextJS 的新手,我正在使用 v13.4.3。我的后端正在执行身份验证,并且在登录时,它会返回一个 JWT 作为附加到浏览器的 HTTPONLY cookie。我的要求是构建组件...

回答 1 投票 0

OAuth 2.0 - 授权代码流程 - 安全问题

我对 OAuth 2 标准中的授权代码流程有一些担忧。 客户端密钥仅用于授权 API 客户端访问用户资源还是用于签名...

回答 1 投票 0

© www.soinside.com 2019 - 2024. All rights reserved.