Skip to content

Commit

Permalink
Merge pull request #429 from senacor/improve_documentation
Browse files Browse the repository at this point in the history
Improve documentation
  • Loading branch information
ziegler-daniel authored Oct 11, 2024
2 parents ac1586b + ef6c2d7 commit b5cd23a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
14 changes: 14 additions & 0 deletions example/request.http
Original file line number Diff line number Diff line change
@@ -1 +1,15 @@
### Call function test-header-authentication-function
POST http://localhost:8080/api/authentication
x-ms-client-principal-id: 42

### Call function test-jwt-authorization-function
POST http://localhost:8080/api/authorization/user-id
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ1c2VyLWlkIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.UtSlzAkI3g8amFZFZcsismCy0f_MZD7lOQ5zgJn5FJU

### Call function test-validation-function
POST http://localhost:8080/api/validation
Content-Type: application/json

{
"name": "John Doe"
}
12 changes: 10 additions & 2 deletions example/src/test-jwt-authorization-function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,16 @@ import { HttpHandler, HttpRequestParams, app } from '@azure/functions';
import { middleware } from '../../src';
import authorization from '../../src/jwtAuthorization';

type JwtClaims = {
sub: string;
name: string;
};

export const handler: HttpHandler = async (req, context) => {
context.log('Function called');
const jwtClaims = context.extraInputs.get('jwt') as JwtClaims;

context.log(`Function called by ${JSON.stringify(jwtClaims)}`);

return { status: 204 };
};

Expand All @@ -17,7 +25,7 @@ app.http('test-jwt-authorization-function', {
authorization([
{
parameterExtractor: (parameters: HttpRequestParams) => parameters.id,
jwtExtractor: (jwt: { userId: string }) => jwt.userId,
jwtExtractor: (jwt: { sub: string }) => jwt.sub,
},
]),
],
Expand Down
4 changes: 2 additions & 2 deletions integration-test/jwt-authorization-test.integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import axios from 'axios';

import waitTillFunctionReady from './waitTillFunctionReady';

// Token generated with https://jwt.io/ containing the "userId" "c8e65ca7-a008-4b1c-b52a-4ad0ee417017"
// Token generated with https://jwt.io/ containing the "sub" "c8e65ca7-a008-4b1c-b52a-4ad0ee417017"
const sampleToken =
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOiJjOGU2NWNhNy1hMDA4LTRiMWMtYjUyYS00YWQwZWU0MTcwMTcifQ.EvY_4nO-uZrc2mNY9E-RvLb5CI-q5tzv1pwBhFaUWgs';
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJjOGU2NWNhNy1hMDA4LTRiMWMtYjUyYS00YWQwZWU0MTcwMTciLCJuYW1lIjoiSm9obiBEb2UiLCJpYXQiOjE1MTYyMzkwMjJ9.TYD4sZM42CWiIPlKm4n2uesaGHRi_priukmc4xSn0K0';

describe('The example azure function is started and the JWT authorization should execute the request', () => {
beforeAll(async () => {
Expand Down

0 comments on commit b5cd23a

Please sign in to comment.