简体   繁体   中英

Using ASP.NET Identity in Azure Functions

I'm developing a WebApp with VueJS as the frontend and Azure Functions as the backend. 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.

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>(...); 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 . For this, you just have to do configurational set-up on the portal.

Step 1:

在此处输入图片说明

Step 2:

在此处输入图片说明

Step 3:

在此处输入图片说明

Step 4:

在此处输入图片说明

And later on automate it through ARM templates.

You can refer to this tutorial for the same: Azure AD authentication in Azure Functions

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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