azure-functions-auth
Authentication and Authorization for Azure Functions (with OAuth 2.0 and JWT)
Configuration
const validateJwt = clientId: '<client id>' clientSecret: '<client secret or IDP\'s public key / signing certificate>' domain: '<your IDP>' algorithms: 'RS256';
Usage
Callback Style
moduleexports = ;
In case of an invalid JWT context.res
gets populated accordingly and context.done()
gets called.
Async Style
const main = { context return { }}moduleexports =
In case of an invalid JWT a specific error and status code get returned. Make sure to have your function host is configured to use function's return value.
Regarding the http output your function.json
should look like the above.
moduleexports = run: main
In order to do tests, of course you still can export your functions.
Calling your function
Now when you make a call to the Http endpoint you'll need to add an Authorization header, e.g.:
GET https://functionsad5bb49d.azurewebsites.net/api/my-http-function?...Authorization: Bearer the-access-token
Attribution
This code is based on https://github.com/sandrinodimattia/azure-functions-auth0