Skip to content
This repository has been archived by the owner on Nov 28, 2022. It is now read-only.

feat: adding support for cookie auth #817

Merged
merged 5 commits into from
Jul 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion example/swagger-files/auth-types.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,21 @@
}
]
}
},
"/anything/apiKey-cookie": {
"post": {
"summary": "ApiKey security type via cookie",
"responses": {
"200": {
"description": "OK"
}
},
"security": [
{
"apiKeyCookie": []
}
]
}
}
},
"components": {
Expand All @@ -89,10 +104,15 @@
"type": "apiKey",
"in": "query",
"name": "apiKey"
},
"apiKeyCookie": {
"type": "apiKey",
"in": "cookie",
"name": "apiKey"
}
}
},
"x-explorer-enabled": true,
"x-samples-enabled": true,
"x-samples-languages": ["curl", "node", "ruby", "javascript", "python"]
"x-samples-languages": ["curl", "node", "node-simple", "ruby", "javascript", "python"]
}
6 changes: 3 additions & 3 deletions packages/api-explorer/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/api-explorer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"@readme/markdown-magic": "^6.12.0",
"@readme/oas-extensions": "^6.10.2",
"@readme/oas-to-har": "^6.12.1",
"@readme/oas-tooling": "^3.4.7",
"@readme/oas-tooling": "^3.5.0",
"@readme/react-jsonschema-form": "^1.1.5",
"@readme/syntax-highlighter": "^6.10.2",
"@readme/variable": "^6.10.2",
Expand Down
32 changes: 32 additions & 0 deletions packages/oas-to-har/__tests__/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1171,6 +1171,38 @@ describe('auth', () => {
]);
});

it('should work for cookie', () => {
expect(
oasToHar(
new Oas({
components: {
securitySchemes: {
'auth-cookie': {
type: 'apiKey',
name: 'authCookie',
in: 'cookie',
},
},
},
}),
{
path: '/security',
method: 'get',
security: [{ 'auth-cookie': [] }],
},
{},
{
'auth-cookie': 'value',
}
).log.entries[0].request.cookies
).toStrictEqual([
{
name: 'authCookie',
value: 'value',
},
]);
});

it('should work for multiple (||)', () => {
expect(
oasToHar(
Expand Down
6 changes: 3 additions & 3 deletions packages/oas-to-har/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/oas-to-har/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"main": "src/index.js",
"dependencies": {
"@readme/oas-extensions": "^6.10.2",
"@readme/oas-tooling": "^3.4.7"
"@readme/oas-tooling": "^3.5.0"
},
"scripts": {
"inspect": "jsinspect",
Expand Down
5 changes: 5 additions & 0 deletions packages/oas-to-har/src/lib/configure-security.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ module.exports = function configureSecurity(oas, values, scheme) {
}

return harValue('headers', header);
} else if (security.in === 'cookie') {
return harValue('cookies', {
name: security.name,
value: values[scheme],
});
Copy link
Member Author

@erunion erunion Jul 1, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:easy:

}
}

Expand Down