Skip to content

Commit

Permalink
rename auth header from authentication to authorization (#47)
Browse files Browse the repository at this point in the history
  • Loading branch information
Miłosz Skaza authored Dec 28, 2022
1 parent fc0350c commit edcc767
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/routes/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ export default (

const getIssueTokenHandler = (fastify: FastifyInstance) => {
return async (request: FastifyRequest, reply: FastifyReply) => {
const { authentication } = <IssueTokenRequestHeadersType>request.headers;
const { authorization } = <IssueTokenRequestHeadersType>request.headers;
const { validity, scope, strict } = <IssueTokenRequestType>request.body;

if (!authenticateIssuerToken(authentication, fastify.config.SECRET)) {
if (!authenticateIssuerToken(authorization, fastify.config.SECRET)) {
return reply.status(401).send({
statusCode: 401,
error: "Invalid Issuer Token",
Expand Down
2 changes: 1 addition & 1 deletion src/schemas/auth.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Static, Type } from "@sinclair/typebox";

export const IssueTokenRequestHeaders = Type.Object({
authentication: Type.String(),
authorization: Type.String(),
});
export type IssueTokenRequestHeadersType = Static<typeof IssueTokenRequestHeaders>;

Expand Down
14 changes: 7 additions & 7 deletions tests/auth.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ test("POST '/api/v1/issue-token' issues token with default values", async (t) =>
scope: "https://example.com",
},
headers: {
Authentication: `Bearer ${TEST_ISSUER_TOKEN}`,
Authorization: `Bearer ${TEST_ISSUER_TOKEN}`,
},
});

Expand Down Expand Up @@ -105,7 +105,7 @@ test("POST '/api/v1/issue-token' issues token with custom validity", async (t) =
validity: 3600,
},
headers: {
Authentication: `Bearer ${TEST_ISSUER_TOKEN}`,
Authorization: `Bearer ${TEST_ISSUER_TOKEN}`,
},
});

Expand Down Expand Up @@ -137,7 +137,7 @@ test("POST '/api/v1/issue-token' issues token with strict attribute", async (t)
strict: true,
},
headers: {
Authentication: `Bearer ${TEST_ISSUER_TOKEN}`,
Authorization: `Bearer ${TEST_ISSUER_TOKEN}`,
},
});

Expand All @@ -155,7 +155,7 @@ test("POST '/api/v1/issue-token' issues token with strict attribute", async (t)
t.assert(payload.iat! >= stamp);
});

test("POST '/api/v1/issue-token' rejects requests without authentication", async (t) => {
test("POST '/api/v1/issue-token' rejects requests without authorization", async (t) => {
const { app } = t.context;

const response = await app.inject({
Expand All @@ -171,11 +171,11 @@ test("POST '/api/v1/issue-token' rejects requests without authentication", async
t.deepEqual(body, {
statusCode: 400,
error: "Bad Request",
message: "headers must have required property 'authentication'",
message: "headers must have required property 'authorization'",
});
});

test("POST '/api/v1/issue-token' rejects requests with invalid authentication", async (t) => {
test("POST '/api/v1/issue-token' rejects requests with invalid authorization", async (t) => {
const { app } = t.context;

const response = await app.inject({
Expand All @@ -186,7 +186,7 @@ test("POST '/api/v1/issue-token' rejects requests with invalid authentication",
},
headers: {
// correctly signed visit token - but not an issuer token
Authentication: `Bearer ${TEST_TOKEN}`,
Authorization: `Bearer ${TEST_TOKEN}`,
},
});

Expand Down
4 changes: 2 additions & 2 deletions tests/snapshots/swagger.test.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ Generated by [AVA](https://avajs.dev).
parameters: [
{
in: 'header',
name: 'authentication',
name: 'authorization',
required: true,
schema: {
type: 'string',
Expand Down Expand Up @@ -1043,7 +1043,7 @@ Generated by [AVA](https://avajs.dev).
parameters: [
{
in: 'header',
name: 'authentication',
name: 'authorization',
required: true,
schema: {
type: 'string',
Expand Down
Binary file modified tests/snapshots/swagger.test.ts.snap
Binary file not shown.

0 comments on commit edcc767

Please sign in to comment.