简体   繁体   English

在 Azure Functions 中使用 ASP.NET 标识

[英]Using ASP.NET Identity in Azure Functions

I'm developing a WebApp with VueJS as the frontend and Azure Functions as the backend.我正在开发一个以 VueJS 作为前端和 Azure Functions 作为后端的 WebApp。 This app will be for internal company use, so no social network logins.此应用程序将供公司内部使用,因此无需登录社交网络。 So we plan to use AspNetCore Identity which is mature and seems to work with Functions, just not found how yet.所以我们计划使用成熟的 AspNetCore Identity,它似乎可以与 Functions 一起使用,只是还没有找到。

I managed to get Dependency Injection working for the Functions :我设法让依赖注入为函数工作:

public class Startup : FunctionsStartup
{
    public override void Configure(IFunctionsHostBuilder builder)
    {
        string conn = Environment.GetEnvironmentVariable("sqldb_connection");
        
        builder.Services.Configure<IdentityOptions>(options =>
        {
            options.Password.RequireDigit = true;
            options.Password.RequireLowercase = true;
            options.Password.RequireNonAlphanumeric = true;
            options.Password.RequireUppercase = true;
            options.Password.RequiredLength = 6;
            options.Password.RequiredUniqueChars = 1;

            options.SignIn.RequireConfirmedEmail = false;
            options.SignIn.RequireConfirmedPhoneNumber = false;

            options.User.RequireUniqueEmail = true;
        });
        
        builder.Services.AddDbContext<DatabaseContext>(o =>
        {
            o.UseSqlServer(conn ?? throw new NullReferenceException("Environment Variable is Null"));
        });
        
        builder.Services.AddIdentity<IdentityUser, IdentityRole>()
            .AddEntityFrameworkStores<DatabaseContext>();

        builder.Services.AddAuthentication(options =>
        {
            options.AddScheme<JwtBearerHandler>("JWT", "JWT Bearer Handler");
        });
    }
}

I have no idea if AddScheme<JwtBearerHandler>(...);我不知道AddScheme<JwtBearerHandler>(...); is the way to go, and no idea how to use it if it is.是要走的路,如果是的话,不知道如何使用它。 I found this to consume the token, but how do I create it?我发现会消耗令牌,但如何创建它?

As far as I know and understand form your question, you want to set-up Azure AD in your Azure functions .据我了解和理解你的问题,你想在你的Azure 函数中设置Azure AD For this, you just have to do configurational set-up on the portal.为此,您只需在门户上进行配置设置。

Step 1:第1步:

在此处输入图片说明

Step 2:第2步:

在此处输入图片说明

Step 3:第 3 步:

在此处输入图片说明

Step 4:第四步:

在此处输入图片说明

And later on automate it through ARM templates.稍后通过 ARM 模板将其自动化。

You can refer to this tutorial for the same: Azure AD authentication in Azure Functions您可以参考本教程: Azure Functions 中的 Azure AD 身份验证

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM