https://github.com/optum/azure-functions-auth
TypeScript package for adding OAuth2 to Azure Functions
https://github.com/optum/azure-functions-auth
azure-functions oauth2
Last synced: about 1 month ago
JSON representation
TypeScript package for adding OAuth2 to Azure Functions
- Host: GitHub
- URL: https://github.com/optum/azure-functions-auth
- Owner: Optum
- License: apache-2.0
- Created: 2022-08-10T21:30:24.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2023-02-16T19:55:44.000Z (over 3 years ago)
- Last Synced: 2025-02-08T15:16:39.978Z (over 1 year ago)
- Topics: azure-functions, oauth2
- Language: TypeScript
- Homepage:
- Size: 31.3 KB
- Stars: 2
- Watchers: 7
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
- Codeowners: CODEOWNERS
Awesome Lists containing this project
README
# azure-functions-auth
An easy way to wrap Azure Functions in automatic OAuth2 JWT authorization!
This library will wrap any javascript/typescript Azure Function implementation and automatically provide access to
the JwtToken that was included on the request. If the auth requirements weren't met, 401/403 responses are
automatically sent back.
Examples:
# Require a JWT token with no role requirements
```typescript
import { requireAuthorization, AuthenticatedContext } from "@optum/azure-functions-auth"
const httpTrigger: AzureFunction = requireAuthorization(async (context: AuthenticatedContext, req: HttpRequest): Promise => {
context.log("Received request from subject", context.jwtToken.sub)
}, {
jwksEndpoint: process.env.JWKS_ENDPOINT, // configurable based on your OAuth2 provider
requiredIssuer: process.env.REQUIRED_ISSUER, // configurable based on your OAuth2 provider
requiredAud: process.env.REQUIRED_AUD // the specific audiance value for your service
})
export default httpTrigger
```
# Require a JWT token with additional role requirements
```typescript
import { requireAuthorization, AuthenticatedContext } from "@optum/azure-functions-auth"
const httpTrigger: AzureFunction = requireAuthorization(async (context: AuthenticatedContext, req: HttpRequest, token: JwtToken): Promise => {
context.log("Received request from subject", context.jwtToken.sub)
}, {
jwksEndpoint: process.env.JWKS_ENDPOINT, // configurable based on your OAuth2 provider
requiredIssuer: process.env.REQUIRED_ISSUER, // configurable based on your OAuth2 provider
requiredAud: process.env.REQUIRED_AUD, // the specific audiance value for your service
requiredRole: "MY_FUNCTION_ROLE" // the role guarding access to this specific function endpoint
})
export default httpTrigger
```