azure-functions-core-tools icon indicating copy to clipboard operation
azure-functions-core-tools copied to clipboard

How can I test azure function with https easily in local?

Open nanan1993 opened this issue 5 years ago • 6 comments

I want to test Azure Function Http trigger locally on windows.

When I run func start --port 5007 --useHttps I got error : Auto cert generation is currently not working on the .NET Core build.

It seems like that I should use command func start --port 5007 --useHttps --cert certificate.pfx after I creating a self-signed certificate locally.

Is there a way to enable https easily?

The way like when I use .net core webapi, I easily export env:ASPNETCORE_URLS=https://localhost. Then I set up https well. Do we have some thing like this?

Or if func start --port 5007 --useHttps is enough but I missed some configuration?

nanan1993 avatar Jun 18 '20 16:06 nanan1993

@nanan1993 Can you share the full output of the command? It should show some instructions on how to set up a cert. Also, what platform are you running on? Thanks.

anthonychu avatar Jun 18 '20 18:06 anthonychu

Thanks for your quick reply. I worked on Win10 locally. Here is the instructions you mentioned and I know how it will work. K4c6b I am wondering if we can straightly use command func host start --port 5007 --useHttps to start but not to add "--cert certificate.pfx" every time. As I remember, when testing webapi, I do not need to know where the .pfx file is. What exactly I want is a way to automatically generate a default debug cert and use it when start functions. So that I do not necessarily need to create a cert file by myself. Creating, Trusting , Adding cert file ... all the things will be done by tools, I just need to say "hey, I want a https trigger" and every thing prepared for me like a magic. As I know webapi did it when I debug. Do we have it in azure function?

nanan1993 avatar Jun 19 '20 02:06 nanan1993

With azure core tools version 4.0, it appears that --useHttps works fine to generate a self-signed certificate:

(.venv) PS C:\azure> func start --useHttps
Found Python version 3.9.13 (py).

Azure Functions Core Tools
Core Tools Version:       4.0.5198 Commit hash: N/A  (64-bit)
Function Runtime Version: 4.21.1.20667

Generating a self signed certificate using openssl

Functions:

...

MHebes avatar Jun 21 '23 21:06 MHebes

Hm... I get:

(.venv) PS C:\Users\me\Documents\projects\myproject> func start --useHttps
Found Python version 3.8.10 (py).

Azure Functions Core Tools
Core Tools Version:       4.0.5348 Commit hash: N/A  (64-bit)
Function Runtime Version: 4.24.5.21262

Auto cert generation is currently not working on the .NET Core build.
On Windows you can run:

PS> $cert = New-SelfSignedCertificate -Subject localhost -DnsName localhost -FriendlyName "Functions Development" -KeyUsage DigitalSignature -TextExtension @("2.5.29.37={text}1.3.6.1.5.5.7.3.1")
PS> Export-PfxCertificate -Cert $cert -FilePath certificate.pfx -Password (ConvertTo-SecureString -String <password> -Force -AsPlainText)

For more checkout https://docs.microsoft.com/en-us/aspnet/core/security/https

Auto cert generation is currently not working on the .NET Core build.

ericthomas1 avatar Nov 06 '23 23:11 ericthomas1

@ericthomas1 you are probably using pwsh... try the 'old' powershell

ghost avatar Jan 03 '24 15:01 ghost

Any plans to get the certificate generation working?

adae-palfinger avatar Oct 10 '25 11:10 adae-palfinger