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

OpenAPI SecuritySchemes are ignored #12

Open
Rafael17 opened this issue Nov 8, 2024 · 0 comments
Open

OpenAPI SecuritySchemes are ignored #12

Rafael17 opened this issue Nov 8, 2024 · 0 comments

Comments

@Rafael17
Copy link

Rafael17 commented Nov 8, 2024

Hi! I have an openapi.json with the following security scheme:

"components": {
    "securitySchemes": {
      "OAuth2": {
        "type": "oauth2",
        "flows": {
          "authorizationCode": {
            "authorizationUrl": "https://example.com/oauth/authorize",
            "tokenUrl": "https://example.com/oauth/token",
            "scopes": {
              "read": "Grants read access",
              "write": "Grants write access",
              "admin": "Grants access to admin operations"
            }
          }
        }
      }
    },
    "schemas": {}
  },

and one of the endpoint uses it like this

"/example/{id}": {
  "get": {
    "parameters": [
      {
        "schema": {
          "minLength": 1,
          "type": "string"
        },
        "in": "path",
        "name": "id",
        "required": true
      }
    ],
    "security": [
      {
        "OAuth2": [
          "read"
        ]
      }
    ]
  }

I'm also extending fetch to add an interceptor for Auth:

export const fetchWithInterceptor = (input: URL | RequestInfo, options?: RequestInit | undefined) => {
  const token = getAuthToken();
  const headers = {
    'Content-Type': 'application/json',
    'Authorization': `Bearer ${token}`,
    ...options?.headers,
  };

  return fetch(input, {
    ...options,
    headers,
  });
};

const client = createClient({
  schema,
  baseUrl: 'https://example.com',
  fetch: fetchWithInterceptor
})

However, it seems like securitySchemes is ignored, so I'm not able to get authorizationCode details to properly create the interceptor, since some endpoints use different schemas.

Any thoughts on how I should implement Authentication?

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