1

I have an Azure function app. It works well with HTTP locally. Also it works well on production. I am trying to run it with HTTPS locally. I created a certificate but it's still showing a certificate error on the browser. I tried to add my certificate to KeyChain Access as well but the result is the same.

How can I run my function with an SSL certificate locally?

I'am trying to access my service from my mobile app but android is not allowing me to call a HTTP endpoint.

Thanks.

cinaarss
  • 43
  • 1
  • 8

1 Answers1

1

The command line arguments need to be set correctly, and then the Azure Functions can be started in Visual Studio with HTTPS and take advantage of the break point debugging without having to attach the func process in Visual Studio.

  1. Install the tools for local Azure Function development: Microsoft Azure Storage Explorer Microsoft Azure Storage Emulator Install the Azure Functions Core Tools Or npm install -g azure-functions-core-tools

  2. Install the Azure Functions Visual Studio Extensions

Azure Functions and Web Jobs Tools need to be installed as an extension in Visual Studio.

enter image description here

  1. Configure the Azure Functions project to use HTTPS

Create a certificate and add this to the operating system.

openssl genrsa -des3 -passout pass:x -out server.pass.key 2048

openssl rsa -passin pass:x -``in server.pass.key -out server.key

openssl req -``new -key server.key -out server.csr

openssl x509 -req -sha256 -days 365 -``in server.csr -signkey server.key -out server.crt

or

New-SelfSignedCertificate -DnsName "server.com"``, "server.com" -CertStoreLocation "cert:\LocalMachine\My"

Get the thumbprint for later use

$mypwd = ConvertTo-SecureString -String "1111" -Force -AsPlainText

Get-ChildItem -Path cert:\localMachine\my\``"thumbprint from above" | Export-PfxCertificate -FilePath C:\server.pfx -Password $mypwd

  1. Copy the pfx file to the Function project and then configure the properties to copy this to the output.

enter image description here

  1. Configure the command line arguments for Debug.
  2. The application arguments starts with host in Visual Studio and not func! This would be func in the command line.

enter image description here

Or just set this in the launchSettings.json

{

"profiles"``: {
"FunctionApp1": {
"commandName":` "Project",
"commandLineArgs": "host start --useHttps --cert \"server.pfx\" --password \"1111\""
        }
    }
}

When you start the Azure Function project with Visual Studio, the HTTPS URL will be used. This can be checked in the command line window which opens up after starting. Break point debugging is now possible as we started from Visual Studio.

enter image description here

If you start this from the console using the func start –useHttps –cert “server.pfx” –password “1111”, you need to attach the func process for break point debugging for using Visual Studio.