Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do we support Cookie Authentication? #70

Open
tmyl123 opened this issue Aug 8, 2021 · 0 comments
Open

Do we support Cookie Authentication? #70

tmyl123 opened this issue Aug 8, 2021 · 0 comments

Comments

@tmyl123
Copy link

tmyl123 commented Aug 8, 2021

OpenAPI 3.0 has support for describing cookie authentication, it's a type of apiKey with in: cookie.

Since HTTP Snippet also support cookies, can we just leverage the cookies over here.

const har = {
method: method.toUpperCase(),
url: baseUrl + getFullPath(openApi, path, method),
headers: getHeadersArray(openApi, path, method),
queryString: getQueryStrings(openApi, path, method, queryParamValues),
httpVersion: 'HTTP/1.1',
cookies: [],
headersSize: 0,
bodySize: 0,
};

Here's the fork I'm using for cookie authentication, I'm fairly new to OpenAPI stuff, so just assume where cookies can only been taken from security relative sections.

Test Input

const OpenAPISnippet = require("openapi-snippet");
const openApi = {
    servers: [
        {
            url: "http://api.example.com/api/v1",
        },
    ],
    paths: {
        "/books": {
            post: {
                security: [
                    {
                        cookieAuth: [],
                    },
                ],
            },
        },
    },
    components: {
        securitySchemes: {
            cookieAuth: {
                type: "apiKey",
                in: "cookie",
                name: "my-session",
            },
        },
    },
    security: [
        {
            cookieAuth: [],
        },
    ],
};
const targets = ["shell_curl"];

try {
    // console.log(openApi);
    const results2 = OpenAPISnippet.getEndpointSnippets(
        openApi,
        "/books",
        "post",
        targets
    );
    console.log(results2);
} catch (err) {
    console.log(err);
}

Output

{
  method: 'POST',
  url: 'http://api.example.com/api/v1/books',
  description: undefined,
  resource: 'books',
  snippets: [
    {
      id: 'shell_curl',
      title: 'Shell + Curl',
      content: 'curl --request POST \\\n' +
        '  --url http://api.example.com/api/v1/books \\\n' +
        '  --cookie my-session=REPLACE_KEY_VALUE'
    }
  ]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant