Skip to content

Commit 5164eb3

Browse files
authored
Merge pull request #1602 from hey-api/fix/oauth2-flows-sdk
fix: support all oauth2 flows in sdk auth
2 parents 1b73773 + 194f941 commit 5164eb3

File tree

5 files changed

+33
-40
lines changed

5 files changed

+33
-40
lines changed

.changeset/rotten-rabbits-bow.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@hey-api/openapi-ts': patch
3+
---
4+
5+
fix: support all oauth2 flows in sdk auth

packages/openapi-ts/src/plugins/@hey-api/sdk/plugin.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,12 @@ const securitySchemeObjectToAuthObject = ({
128128
securitySchemeObject: IR.SecurityObject;
129129
}): Auth | undefined => {
130130
if (securitySchemeObject.type === 'oauth2') {
131-
// TODO: parser - handle more/multiple oauth2 flows
132-
if (securitySchemeObject.flows.password) {
131+
if (
132+
securitySchemeObject.flows.password ||
133+
securitySchemeObject.flows.authorizationCode ||
134+
securitySchemeObject.flows.clientCredentials ||
135+
securitySchemeObject.flows.implicit
136+
) {
133137
return {
134138
scheme: 'bearer',
135139
type: 'http',

packages/openapi-ts/test/3.1.x.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ describe(`OpenAPI ${version}`, () => {
522522
},
523523
{
524524
config: createConfig({
525-
input: 'security-oauth2.json',
525+
input: 'security-oauth2.yaml',
526526
output: 'security-oauth2',
527527
plugins: [
528528
{
@@ -535,7 +535,7 @@ describe(`OpenAPI ${version}`, () => {
535535
},
536536
{
537537
config: createConfig({
538-
input: 'security-oauth2.json',
538+
input: 'security-oauth2.yaml',
539539
output: 'security-false',
540540
plugins: [
541541
{

packages/openapi-ts/test/spec/3.1.x/security-oauth2.json

Lines changed: 0 additions & 36 deletions
This file was deleted.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
openapi: 3.1.1
2+
info:
3+
title: OpenAPI 3.1.1 security oauth2 example
4+
version: '1'
5+
paths:
6+
/foo:
7+
get:
8+
responses:
9+
'200':
10+
description: OK
11+
security:
12+
- foo: []
13+
components:
14+
securitySchemes:
15+
foo:
16+
flows:
17+
password:
18+
scopes: {}
19+
tokenUrl: '/'
20+
type: 'oauth2'

0 commit comments

Comments
 (0)