BlazorWebAssembly与身份服务器通过表单传递用户名
创始人
2024-12-22 01:00:08
0
  1. 在Blazor WebAssembly应用程序中安装IdentityServer4包。

  2. 创建一个包含用户名的表单并向身份服务器发送请求以进行身份验证。示例代码如下:

@page "/login"
@using System.Net.Http
@using System.Text.Json
@inject HttpClient httpClient

Login

@code { private string UserName { get; set; } private string Password { get; set; } private async Task Login() { var response = await httpClient.PostAsJsonAsync("https://localhost:5001/connect/token", new { client_id = "blazor", client_secret = "secret", grant_type = "password", scope = "api", username = UserName, password = Password }); if (response.IsSuccessStatusCode) { var content = await response.Content.ReadAsStringAsync(); var accessToken = JsonSerializer.Deserialize(content); // Store the access token } else { // Handle error } } class AccessToken { public string access_token { get; set; } public string token_type { get; set; } public int expires_in { get; set; } } }
  1. 在身份服务器上创建授权服务器端点,以便Blazor应用程序可以使用OAuth2对身份进行验证并获取访问令牌。示例代码如下:
public void ConfigureServices(IServiceCollection services)
{
    services.AddIdentity()
        .AddEntityFrameworkStores()
        .AddDefaultTokenProviders();

    services.AddIdentityServer()
        .AddDeveloperSigningCredential()
        .AddInMemoryApiResources(Config.GetApi

相关内容

热门资讯

透视美元局!wpk模拟器多开,... 透视美元局!wpk模拟器多开,德普之星透视辅助软件,2025教程(有挂详细)-哔哩哔哩1、这是跨平台...
透视辅助!hhpoker买挂,... 透视辅助!hhpoker买挂,wpk软件是正规的吗,教你教程(真实有挂)-哔哩哔哩1、wpk软件是正...
透视了解!大菠萝免费辅助,po... 透视了解!大菠萝免费辅助,pokemmo脚本辅助下载,必赢方法(有挂透视)-哔哩哔哩小薇(透视辅助)...
透视美元局!wepoker私人... 透视美元局!wepoker私人局俱乐部辅助,we poker辅助器,靠谱教程(有挂方略)-哔哩哔哩1...
透视免费!wepoker有没有... 透视免费!wepoker有没有透视方法,wejoker辅助机器人,2025新版总结(有挂规律)-哔哩...
透视ai!德普之星透视辅助软件... 透视ai!德普之星透视辅助软件下载,wepoker怎么提高运气,技巧教程(发现有挂)-哔哩哔哩1、完...
透视新版!hhpoker到底可... 透视新版!hhpoker到底可以作弊码,hhpoker辅助挂下载,AI教程(今日头条)-哔哩哔哩1、...
透视游戏!wpk是真的还是假的... 透视游戏!wpk是真的还是假的,德普之星辅助工具如何打开,详细教程(有挂工具)-哔哩哔哩1、德普之星...
透视透视!aapoker怎么提... 透视透视!aapoker怎么提高中牌率,wepoker辅助透视,玩家教程(有挂细节)-哔哩哔哩1)a...
透视了解!大菠萝手游辅助,hh... 透视了解!大菠萝手游辅助,hhpoker是真的还是假的,科技教程(真的有挂)-哔哩哔哩1、让任何用户...