{"id":24068810,"url":"https://github.com/idandaccess/azure-functions-auth","last_synced_at":"2025-04-24T03:10:00.150Z","repository":{"id":26846523,"uuid":"110021059","full_name":"idandaccess/azure-functions-auth","owner":"idandaccess","description":"Authentication and Authorization for Azure Functions (with OAuth 2.0 and JWT)","archived":false,"fork":false,"pushed_at":"2025-04-21T18:46:15.000Z","size":473,"stargazers_count":18,"open_issues_count":39,"forks_count":6,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-24T03:09:51.662Z","etag":null,"topics":["authentication","authorization","azure","azure-functions","identity-management","javascript","jwt","oauth2"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/idandaccess.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2017-11-08T19:30:28.000Z","updated_at":"2024-06-28T21:46:49.000Z","dependencies_parsed_at":"2024-01-05T15:28:37.159Z","dependency_job_id":"ec183391-ded5-489f-97f1-9f8fde8d9835","html_url":"https://github.com/idandaccess/azure-functions-auth","commit_stats":{"total_commits":121,"total_committers":4,"mean_commits":30.25,"dds":"0.25619834710743805","last_synced_commit":"8599c381a2d4a8679c3f41dd687eb1357ea644a2"},"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/idandaccess%2Fazure-functions-auth","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/idandaccess%2Fazure-functions-auth/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/idandaccess%2Fazure-functions-auth/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/idandaccess%2Fazure-functions-auth/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/idandaccess","download_url":"https://codeload.github.com/idandaccess/azure-functions-auth/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250552074,"owners_count":21449165,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["authentication","authorization","azure","azure-functions","identity-management","javascript","jwt","oauth2"],"created_at":"2025-01-09T13:47:35.325Z","updated_at":"2025-04-24T03:10:00.110Z","avatar_url":"https://github.com/idandaccess.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build Status](https://idandaccess.visualstudio.com/azure-functions-auth/_apis/build/status/idandaccess.azure-functions-auth?branchName=master)](https://idandaccess.visualstudio.com/azure-functions-auth/_build/latest?definitionId=2\u0026branchName=master)\n\n# azure-functions-auth\nAuthentication and Authorization for Azure Functions (with OAuth 2.0 and JWT)\n\n## Configuration\n\n```js\nconst validateJwt = require('azure-functions-auth')({\n  clientId: '\u003cclient id\u003e',\n  clientSecret: '\u003cclient secret or IDP\\'s public key / signing certificate\u003e',\n  domain: '\u003cyour IDP\u003e',\n  algorithms: ['RS256'],\n});\n```\n\n## Usage\n### Callback Style\n```js\nmodule.exports = validateJwt(function(context, req) {\n  if (req.user) {\n    context.res = {\n      body: req.user\n    };\n  }\n  else {\n    context.res = {\n      status: 400,\n      body: \"The user property is missing\"\n    };\n  }\n  context.done();\n});\n```\nIn case of an invalid JWT `context.res` gets populated accordingly and `context.done()` gets called.\n\n### Async Style\n```js\nconst main = (context, req) =\u003e {\n  context.log('token is valid. (you shouldn\\'t log like that in production code)')\n  \n  return new Promise(resolve =\u003e {\n    resolve('the function will return this exact string as body with a status code of 200')\n  }).then(asyncResult =\u003e{\n    return asyncResult\n  })\n}\nmodule.exports = validateJwt(main, true)\n```\nIn 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.\n\n```json\n{\n  \"bindings\": [\n    {\n      \"type\": \"http\",\n      \"direction\": \"out\",\n      \"name\": \"$return\"\n    }\n  ]\n}\n```\nRegarding the http output your `function.json` should look like the above.\n\n```js\nmodule.exports = {\n  run: validateJwt(main, true),\n  main\n}\n```\nIn order to do tests, of course you still can export your functions.\n\n### Calling your function\n\nNow when you make a call to the Http endpoint you'll need to add an Authorization header, e.g.:\n\n```bash\nGET https://functionsad5bb49d.azurewebsites.net/api/my-http-function?...\nAuthorization: Bearer the-access-token\n```\n\n\n## Attribution\n\nThis code is based on [https://github.com/sandrinodimattia/azure-functions-auth0](https://github.com/sandrinodimattia/azure-functions-auth0)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fidandaccess%2Fazure-functions-auth","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fidandaccess%2Fazure-functions-auth","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fidandaccess%2Fazure-functions-auth/lists"}