小编saj*_*saj的帖子

使用多个身份提供商对 Blazor WebAssembly 进行身份验证

我正在学习 Blazor WebAssembly 并构建一个小项目,以在 Azure 中作为静态 Web 应用程序托管。

目标框架是net5.0。

当用户单击“登录”超链接或按钮时,新页面将显示一些身份提供商的名称(Microsoft、Google、SackOverflow 等)。然后用户将选择其中之一进行登录。

我只使用一个身份提供商(仅 Microsoft、仅 Google 等)来完成此操作。

如何在同一个应用程序中使用多个身份提供商?

有人可以帮助我吗?

Blazor WebAssembly 应用程序

目标框架:net5.0

在 Azure 中作为静态 Web 应用程序托管

程序.cs

using Blazored.LocalStorage;

using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;

using System;
using System.Net.Http;
using System.Threading.Tasks;

namespace FileProcApp
{
    public class Program
    {
        public static async Task Main(string[] args) {
            var builder = WebAssemblyHostBuilder.CreateDefault(args);
            builder.RootComponents.Add<App>("#app");

            builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });

            builder.Services.AddOidcAuthentication(options => {
                options.ProviderOptions.DefaultScopes.Clear();
                options.ProviderOptions.DefaultScopes.Add("openid");
                options.ProviderOptions.DefaultScopes.Add("offline_access");
                builder.Configuration.Bind("AzureAd", options.ProviderOptions);
            });
            
            builder.Services.AddOidcAuthentication(options …
Run Code Online (Sandbox Code Playgroud)

c# authentication blazor-webassembly

6
推荐指数
0
解决办法
491
查看次数

Mongo DB对象Id使用JSON序列化程序进行反序列化

var docToJson = doc.ToJson<BsonDocument>();
story Featured = JsonConvert.DeserializeObject<story>(docToJson);


public class story 
{
[JsonProperty("_id"), JsonConverter(typeof(ObjectIdConverter))]
public ObjectId Id { get; set; }
....

public class ObjectIdConverter : JsonConverter
{
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            serializer.Serialize(writer, value.ToString());
        }

        public override object ReadJson(JsonReader reader, Type objectType, object existingValue,        

 JsonSerializer serializer)
        {
            JToken token = JToken.Load(reader);
            return new ObjectId(token.ToObject<string>());
        }

        public override bool CanConvert(Type objectType)
        {
            return (objectType == typeof(ObjectId));
        }
      }
    }
Run Code Online (Sandbox Code Playgroud)

我被困了我已经尝试了六种方法,我仍然得到与json读者相同的错误,任何人的想法?

最后从SO*尝试过这个

JsonReader异常

解析值时遇到意外的字符:O.路径'_id',第1行,第10位. …

c# azure json.net mongodb deserialization

5
推荐指数
1
解决办法
7025
查看次数

驱动程序中缺少 MongoDB 驱动程序(查询生成器)?

驱动程序

嗨,我正在尝试更新一些代码以使用异步更新的 mongo 驱动程序,一切顺利,但是我无法从 Mongodb.Drivers.Builders.Query 中找到 QUERY,它去哪儿了?我应该在它的地方使用什么?或者使用较新的驱动程序安装旧驱动程序是否安全?

我找不到 MongoDB.Driver.Builders 命名空间???

顺便说一句,这是查询以防万一有新东西

var queryplaces = Query.WithinCircle("Loc", lon, lat, maxDistanceInRadians);
Run Code Online (Sandbox Code Playgroud)

c# mongodb mongodb-query

4
推荐指数
1
解决办法
8248
查看次数

如何在Startup.cs中注册Generic类型的接口

我在ASP.NET Core中使用WebAPI.

这有效:

services.AddScoped<IApiKeysService, APIKeysService>();
Run Code Online (Sandbox Code Playgroud)

现在接口返回泛型类型T这不是

services.AddScoped<IApiKeysService>();
Run Code Online (Sandbox Code Playgroud)

错误使用泛型类型blah需要1种类型的参数

或这个

services.AddScoped<IApiKeysService<T>>();
Run Code Online (Sandbox Code Playgroud)

我得到以下编译错误

无法找到类型或命名空间T.

我该如何注册Startup.cs

注意:我不能使用具体类型,因为接口成员是具有泛型方法的基类.

c# generics dependency-injection .net-core asp.net-core

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

ASP.NET核心标识中的角色声明的JWT身份验证

我如何通过声明对用户进行身份验证,其中包含用户角色?

Startup.cs:

services.AddAuthorization(options => {
                options.AddPolicy("CanEdit", policy => policy.RequireClaim("CanEdit"));    
});
Run Code Online (Sandbox Code Playgroud)

在登录控制器中我有:

    private async ValueTask<JwtSecurityToken> GetJwtSecurityToken(ApplicationUser user){
        //var totalClaims = new List<Claim>();
        //var userRoles = await _userManager.GetRolesAsync(user);
        //foreach (var role in userRoles) {
        //    var roleClaims = await _roleManager.GetClaimsAsync(await _roleManager.Roles.SingleAsync(r => r.Name.Equals(role)));
        //    totalClaims.AddRange(roleClaims);
        //}
        var claims = new List<Claim>
        {
            new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString()),
            new Claim(JwtRegisteredClaimNames.Sub, user.UserName),
            new Claim(JwtRegisteredClaimNames.Email, user.Email)
        };
        return new JwtSecurityToken(
            _configuration["Token:Issuer"],
            _configuration["Token:Audience"],
            //totalClaims,
            claims
            expires: DateTime.UtcNow.AddHours(12),
            signingCredentials: new SigningCredentials(
                new SymmetricSecurityKey(Encoding.UTF8.GetBytes(_configuration["Token:Key"])),
                SecurityAlgorithms.HmacSha256)
        );
    }
Run Code Online (Sandbox Code Playgroud)

方法 …

c# jwt asp.net-identity asp.net-core asp.net-core-webapi

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

来自react-router-dom Home的Navlink始终处于活动状态

导航工作,家庭链接总是活跃其他链接都可以.添加为组件,没有道具.

HTML

 <Menu/>
Run Code Online (Sandbox Code Playgroud)

CSS

.active{
background-color:#ff6a00;
}
Run Code Online (Sandbox Code Playgroud)

JS

import React, { Component } from 'react';
import './menu.css';
import { NavLink } from 'react-router-dom'
export default class TopMenu extends Component {

 render() {
    return (
        <div className="ui container">
            <div className="ui stackable menu">
                <div className="item">
                    <NavLink to='/' >
                        <i aria-hidden="true" className="home  icon" ></i>
                        Home
                     </NavLink>
                </div>
                <div className="item">
                    <NavLink to='/about' >
                        <i aria-hidden="true" className="circle info  icon" > 
                        </i>
                        About
                    </NavLink>
                </div>

                <div className="item" >
                    <NavLink to='/Settings'>
                        <i aria-hidden="true" className="cogs icon red" ></i> …
Run Code Online (Sandbox Code Playgroud)

reactjs react-router-dom

0
推荐指数
3
解决办法
965
查看次数