-
Notifications
You must be signed in to change notification settings - Fork 41
/
Startup.cs
47 lines (38 loc) · 1.91 KB
/
Startup.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
using Microsoft.Azure.Functions.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection;
using Contoso.Orders.FunctionApp;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.Identity.Web;
[assembly: FunctionsStartup(typeof(Startup))]
namespace Contoso.Orders.FunctionApp
{
public class Startup : FunctionsStartup
{
public override void Configure(IFunctionsHostBuilder builder)
{
var configuration = builder.GetContext().Configuration;
builder.Services.AddLogging();
builder.Services.AddAuthenticationCore(c =>
{
c.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
c.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
}).AddMicrosoftIdentityWebApiAuthentication(configuration);
builder.Services.Configure<JwtBearerOptions>(JwtBearerDefaults.AuthenticationScheme,
options =>
{
options.TokenValidationParameters.IssuerValidator = (issuer, token, parameters) =>
{
// Here we can validate the issuer reading for example a list
// of issuers (i.e. subscribed tenants) from a data repository
// Then, to confirm that the issuer is valid, we simply return
// the issuer itself
// For the sake of simplicity, in this sample API we accept any issuer
return issuer;
// But in case of an invalid issuer, you could throw the following exception
//throw new SecurityTokenInvalidIssuerException(
// $"IDW10303: Issuer: '{issuer}', does not match any of the valid issuers provided for this application.");
};
});
}
}
}