Skip to content

Add support for all OAuth2 flows in securitySchemes configuration #1599

@danielsharvey

Description

@danielsharvey

Description

I received this error:

❗️ SDK warning: unsupported security scheme. Please open an issue if you'd like it added https://github.com/hey-api/openapi-ts/issues
{
  "type": "oauth2",
  "flows": {
    "authorizationCode": {
      "authorizationUrl": "/login",
      "tokenUrl": "/oauth/token",
      "scopes": {}
    }
  }
}

I can see that only password is supported presently:

if (securitySchemeObject.type === 'oauth2') {
// TODO: parser - handle more/multiple oauth2 flows
if (securitySchemeObject.flows.password) {
return {
scheme: 'bearer',
type: 'http',
};
}
return;
}

This remains true even in the new feat/security-basic branch:

if (securitySchemeObject.type === 'oauth2') {
if (securitySchemeObject.flows.password) {
security.push({
fn: 'accessToken',
in: 'header',
name: 'Authorization',
});
}

From docs OAuth 2.0 | Swagger Docs the following are valid:

  • authorizationCode – Authorization Code flow (previously called accessCode in OpenAPI 2.0)
  • implicit – Implicit flow
  • password – Resource Owner Password flow
  • clientCredentials – Client Credentials flow (previously called application in OpenAPI 2.0)

Generally, these all use a bearer token for making requests so the implementation (new and old) would apply for each of these. For me, my current workaround is simply to using the password flow when generating.

Can we update (both) branches to accept all of theses flows?

Of note, the main branch includes support for the bearer scheme but this appears to have been remove from the new feat/security-basic branch. It should probably be supported in the same manner as OAuth2?

if (securitySchemeObject.type === 'http') {
if (
securitySchemeObject.scheme === 'bearer' ||
securitySchemeObject.scheme === 'basic'
) {
return {
scheme: securitySchemeObject.scheme,
type: 'http',
};
}
return;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature 🚀New feature or requestprioritized 🚚This issue has been prioritized and will be worked on soon

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions