|
| 1 | +module Program |
| 2 | + |
| 3 | +open Common.Tests |
| 4 | +open DarkLoop.Azure.Functions.Authorization |
| 5 | +open Microsoft.Azure.Functions.Worker |
| 6 | +open Microsoft.Extensions.DependencyInjection |
| 7 | +open Microsoft.Extensions.Hosting |
| 8 | +open Microsoft.IdentityModel.Tokens |
| 9 | + |
| 10 | +// IMPORTANT: because local.settings.json is not included in the repository, you must create it manually |
| 11 | +// If you don't create it. the isolated function will not run. Ensure that the file has the following content: |
| 12 | +// |
| 13 | +// { |
| 14 | +// "IsEncrypted": false, |
| 15 | +// "Values": { |
| 16 | +// "AzureWebJobsStorage": "UseDevelopmentStorage=true", |
| 17 | +// "FUNCTIONS_WORKER_RUNTIME": "dotnet-isolated" |
| 18 | +// } |
| 19 | +// } |
| 20 | + |
| 21 | +let host = |
| 22 | + HostBuilder() |
| 23 | + .ConfigureFunctionsWebApplication(fun builder -> |
| 24 | + //This is needed to make F# variants of startup work nicely |
| 25 | + FunctionsAuthorizationExtensionStartup().Configure(builder) |
| 26 | + builder.UseFunctionsAuthorization() |> ignore ) |
| 27 | + .ConfigureServices(fun services -> |
| 28 | + services |
| 29 | + .AddFunctionsAuthentication(JwtFunctionsBearerDefaults.AuthenticationScheme) |
| 30 | + .AddJwtFunctionsBearer(fun options -> |
| 31 | + // this line is here to bypass the token validation |
| 32 | + // and test the functionality of this library. |
| 33 | + // you can create a dummy token by executing the GetTestToken function in HelperFunctions.cs |
| 34 | + // THE FOLLOWING LINE SHOULD BE REMOVED IN A REAL-WORLD SCENARIO |
| 35 | + options.SecurityTokenValidators.Add(TestTokenValidator()) |
| 36 | + |
| 37 | + // this is what you should look for in a real-world scenario |
| 38 | + // comment the lines if you cloned this repository and want to test the library |
| 39 | + options.Authority <- "https://login.microsoftonline.com/<your-tenant>" |
| 40 | + options.Audience <- "<your-audience>" |
| 41 | + options.TokenValidationParameters <- TokenValidationParameters |
| 42 | + ( |
| 43 | + ValidateIssuer = true, |
| 44 | + ValidateAudience = true, |
| 45 | + ValidateLifetime = true, |
| 46 | + ValidateIssuerSigningKey = true |
| 47 | + ) |
| 48 | + () |
| 49 | + ) |> ignore |
| 50 | + |
| 51 | + services |
| 52 | + .AddFunctionsAuthorization(fun options -> |
| 53 | + // Add your policies here |
| 54 | + () |
| 55 | + ) |> ignore |
| 56 | + ) |
| 57 | + .Build() |
| 58 | + |
| 59 | +host.Run() |
0 commit comments