我正在Azure AD门户中设置应用程序注册,以便与我的示例ASP.Net Core 2 Web应用程序一起使用.对于初学者,我想让基本身份验证工作.我配置这个程序只启用一个许可,"登录和读取用户配置文件",请注意,它并不需要管理员权限:
但是,当我运行我的Web应用程序并尝试对此客户端ID进行身份验证时,我收到"AADSTS90094:授权需要管理员权限"错误:
您无法访问此应用程序
AspNetCoreAdAuth需要权限才能访问组织中只有管理员才能授予的资源.请先让管理员授予此应用程序的权限,然后才能使用它.
这是我的应用用于进行身份验证的网址(删除了一些敏感或不相关的数据):
https://login.microsoftonline.com/<my_tenant_id>/oauth2/authorize?client_id=<my_client_id>&redirect_uri=<my_redirect_uri>&response_type=id_token&scope=openid%20profile&response_mode=form_post&nonce=<gibberish>&state=<giberrish>&x-client-SKU=ID_NET&x-client-ver=2.1.4.0
Run Code Online (Sandbox Code Playgroud)
SO和其他地方的大多数解决方案都建议简单地使用"授予权限"按钮来解决此错误.然而
有任何想法吗?
我有以下类定义:
class Department
{
name: string;
id: string;
get prefix(): string
{
return !isNaN(parseFloat(this.id)) ? "n" : "i" ;
}
}
Run Code Online (Sandbox Code Playgroud)
在我的代码的其他地方,我尝试使用它像这样:
getDepartmentList(): Department[] {
return [
{
"name": "Dept 1",
"id": "1000"
}
];
}
Run Code Online (Sandbox Code Playgroud)
但是,我收到以下错误:
输入'{"name":string; "id":string; }'不能分配给'部门'类型.类型'{"name"中缺少属性'prefix':string; "id":string; }".
我确信真正的问题是我对Typescript缺乏了解,但有人可以解释为什么编译器将getter函数视为属性并希望我在其上设置一个值吗?
假设我有几个接口的实现:
public interface IDemoInterface
{
void DemoMethod();
}
public class DemoClass1 : IDemoInterface
{
public void DemoMethod()
{
Console.WriteLine("DemoClass1");
}
}
public class DemoClass2 : IDemoInterface
{
public void DemoMethod()
{
Console.WriteLine("DemoClass2");
}
}
Run Code Online (Sandbox Code Playgroud)
现在,我正在尝试定义这样的实现的数组,并为每个实现调用接口方法.基本上,做这样的事情(以下是一个非工作代码 - 只是我想要做的一个例子):
public static void Run()
{
var demoClasses = { DemoClass1, DemoClass2};
foreach (var demoClass in demoClasses)
{
var implementation = demoClass as IDemoInterface;
implementation.DemoMethod();
}
}
Run Code Online (Sandbox Code Playgroud)
完成它的最佳方法是什么?使用Reflection是唯一的方法吗?