bearer-token 相关问题

经资源所有者批准,授权服务器向客户端颁发令牌。客户端使用访问令牌来访问资源服务器托管的受保护资源。

使用 IdentityServer 和另一个 JwtBearer 令牌进行身份验证

中央服务将 IdentityServer 作为当前的身份验证方法,需要保持不变。 现在需要支持另一个 Jwt 不记名令牌。 似乎有可能拥有两个令牌...

回答 1 投票 0

在 Power BI 中使用不记名令牌

我正在使用 Power BI 调用不记名令牌。我有不记名令牌,并且可以很轻松地将其调用到 Postman 中。 我尝试在 Power M 中执行空白查询: 让 apiUrl = "my_api_url&qu...

回答 1 投票 0

在 ASP.net Core Razor 页面 WebApp 中读取令牌

我有一个托管在Azure中的asp.net core razor page webapp,使用应用程序注册和AD,到目前为止我可以成功登录、验证并生成不记名令牌。我正在尝试调用 A 中的 API...

回答 1 投票 0

尝试使用请求进行身份验证时出现 Azure AADB2C 错误

我有以下代码,我正在尝试使用 python 请求在azure(Azure Active Directory B2C)中进行身份验证。但是,我收到以下错误。 s_headers = { '权威...

回答 1 投票 0

如何获取在 FastAPI 中作为依赖项传递的 HTTPBearer 令牌的值?

尝试从此 github 存储库学习使用 java-web-tokens 授权的基础知识。在这里复制相关部分以方便参考(我的评论)。 @app.post("/posts",

回答 1 投票 0

如何使用 Axios 从响应标头中获取授权承载令牌?

后端正在响应标头内向我发送一个不记名令牌,我想将其存储在 redux 存储中,因为大多数 API 要求将该令牌发送回标头内。 我是

回答 1 投票 0

如何从响应头中获取 Bearer Token 并将其存储在 Redux Store 中?

后端正在响应标头内向我发送一个不记名令牌,我想将其存储在 redux 存储中,因为大多数 API 要求将该令牌发送回标头内。 我是

回答 1 投票 0

覆盖 ASP.NET Core 中 JWT 中使用的声明键名称

不向系统客户端泄露实现细节被认为是最佳实践。例如,不要使用“Powered by foo”标头进行响应等。 System.Security.Claims.ClaimTypes 包含...

回答 3 投票 0

Spring security Jwt 承载令牌编码/解码错误

当尝试验证用户的 jwt 不记名令牌时,我收到 403 错误,标头告诉我我的令牌范围不足。我想知道在

回答 1 投票 0

401:仅在使用 fetch 请求数据时出现未授权错误

我试图从本地主机上运行的 API 获取响应,我从登录端点获得了生成的不记名令牌,现在我只想使用该令牌来获取用户对其的声明。我的...

回答 2 投票 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

有没有办法为 Azure 中的每个用户获取不记名令牌并用于针对 Web API 进行身份验证?

这似乎是一个非常简单的问题,很难想象微软没有解决方案,但在谷歌搜索几天后我找不到答案,至少不是一个简单的答案。我正在开发...

回答 1 投票 0

如何使用带有不记名令牌的 get 方法在 flutter 中显示来自 api 的数据

我登录后成功显示了我的令牌,此令牌用于登录后访问产品页面。问题是我的产品页面只能显示带有我拥有但我不知道的令牌的数据...

回答 1 投票 0

Strop.js 客户端与 ejabberd X-Oauth2 (Base64) 的问题

我非常需要帮助!我一直在与 Strope.js 进行 OAuth 身份验证方面的斗争,但我已经束手无策了。我已经搜索了文档和示例,但我就是无法获得 OAuth mec...

回答 1 投票 0

Strop.js 客户端与 ejabberd X-Oauth2 的问题

我非常需要帮助!我一直在与 Strope.js 进行 OAuth 身份验证方面的斗争,但我已经束手无策了。我已经搜索了文档和示例,但我就是无法获得 OAuth mec...

回答 1 投票 0

是否可以创建一个 Git 助手或插件来添加 HTTP 标头或强制进行 Bearer Token 身份验证

背景:我们使用 Bitbucket Server(即将升级/切换到 Bitbucket DataCenter)。在我们的身份验证设置中,我们禁用了用户密码(网络身份验证是通过不同的方式),因此对于 Bitbuc...

回答 2 投票 0

无效的 JWT 令牌

我目前正在使用/学习 Json Web 令牌,并学习如何在未来的应用程序中实现受保护的路由,因为我正在关注“学习 Mern Stack”youtube 视频...

回答 1 投票 0

如何访问具有不记名代码且必须先登录的数据Web API?

我尝试发布此API https://newapi.9lottery.cc/api/webapi/GetNoaverageEmerdList,但很难解决。 我尝试了这个但没有用: def halaman1(): 数据 = { '类型ID':'1', ...

回答 1 投票 0

如何使用 Spring boot WebClient 管理 HTTPS 相互身份验证(包括 Bearer Token)?

我的帖子的目的是直接分享我对以下主题的回答。我还分享了对我有帮助的链接 => 我正在开发一个基于 Spring webflux 的后端。前端有角度

回答 1 投票 0

comodo api 身份验证适用于邮递员,但不适用于 google apps 脚本

我正在尝试使用他们的文档通过他们的 API 对 comodo 平台(合作伙伴门户)进行身份验证。 据我了解,我需要使用用户/通行证进行身份验证才能获得持有者...

回答 0 投票 0

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