Skip to content

Commit b767e10

Browse files
authored
Merge pull request #1648 from hey-api/feat/auth-open-id-connect
fix: add support for openIdConnect auth flow
2 parents 3bdc656 + 66a9e45 commit b767e10

File tree

32 files changed

+340
-77
lines changed

32 files changed

+340
-77
lines changed

.changeset/orange-bags-hope.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
---
22
'@hey-api/client-axios': patch
33
'@hey-api/client-fetch': patch
4-
'@hey-api/client-next': patch
54
'@hey-api/client-nuxt': patch
65
---
76

.changeset/tiny-kings-reflect.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
---
22
'@hey-api/client-axios': patch
33
'@hey-api/client-fetch': patch
4-
'@hey-api/client-next': patch
54
'@hey-api/client-nuxt': patch
65
---
76

.changeset/unlucky-ligers-help.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: add support for openIdConnect auth flow

packages/client-core/src/auth.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
11
export type AuthToken = string | undefined;
22

33
export interface Auth {
4+
/**
5+
* Which part of the request do we use to send the auth?
6+
*
7+
* @default 'header'
8+
*/
49
in?: 'header' | 'query';
10+
/**
11+
* Header or query parameter name.
12+
*
13+
* @default 'Authorization'
14+
*/
515
name?: string;
616
scheme?: 'basic' | 'bearer';
717
type: 'apiKey' | 'http';

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

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,19 @@ import {
2828
import { serviceFunctionIdentifier } from './plugin-legacy';
2929
import type { Config } from './types';
3030

31-
// type copied from client packages
32-
interface Auth {
31+
// copy-pasted from @hey-api/client-core
32+
export interface Auth {
33+
/**
34+
* Which part of the request do we use to send the auth?
35+
*
36+
* @default 'header'
37+
*/
3338
in?: 'header' | 'query';
39+
/**
40+
* Header or query parameter name.
41+
*
42+
* @default 'Authorization'
43+
*/
3444
name?: string;
3545
scheme?: 'basic' | 'bearer';
3646
type: 'apiKey' | 'http';
@@ -129,6 +139,13 @@ const securitySchemeObjectToAuthObject = ({
129139
}: {
130140
securitySchemeObject: IR.SecurityObject;
131141
}): Auth | undefined => {
142+
if (securitySchemeObject.type === 'openIdConnect') {
143+
return {
144+
scheme: 'bearer',
145+
type: 'http',
146+
};
147+
}
148+
132149
if (securitySchemeObject.type === 'oauth2') {
133150
if (
134151
securitySchemeObject.flows.password ||

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ describe(`OpenAPI ${version}`, () => {
247247
},
248248
{
249249
config: createConfig({
250-
input: 'security-oauth2.json',
250+
input: 'security-oauth2.yaml',
251251
output: 'security-oauth2',
252252
plugins: [
253253
'@hey-api/client-fetch',
@@ -261,7 +261,7 @@ describe(`OpenAPI ${version}`, () => {
261261
},
262262
{
263263
config: createConfig({
264-
input: 'security-oauth2.json',
264+
input: 'security-oauth2.yaml',
265265
output: 'security-false',
266266
plugins: [
267267
'@hey-api/client-fetch',

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ describe(`OpenAPI ${version}`, () => {
448448
},
449449
{
450450
config: createConfig({
451-
input: 'security-oauth2.json',
451+
input: 'security-oauth2.yaml',
452452
output: 'security-oauth2',
453453
plugins: [
454454
'@hey-api/client-fetch',
@@ -462,7 +462,21 @@ describe(`OpenAPI ${version}`, () => {
462462
},
463463
{
464464
config: createConfig({
465-
input: 'security-oauth2.json',
465+
input: 'security-open-id-connect.yaml',
466+
output: 'security-open-id-connect',
467+
plugins: [
468+
'@hey-api/client-fetch',
469+
{
470+
auth: true,
471+
name: '@hey-api/sdk',
472+
},
473+
],
474+
}),
475+
description: 'generates SDK functions with auth (OpenID Connect)',
476+
},
477+
{
478+
config: createConfig({
479+
input: 'security-oauth2.yaml',
466480
output: 'security-false',
467481
plugins: [
468482
'@hey-api/client-fetch',

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,20 @@ describe(`OpenAPI ${version}`, () => {
537537
}),
538538
description: 'generates SDK functions with auth (oauth2)',
539539
},
540+
{
541+
config: createConfig({
542+
input: 'security-open-id-connect.yaml',
543+
output: 'security-open-id-connect',
544+
plugins: [
545+
'@hey-api/client-fetch',
546+
{
547+
auth: true,
548+
name: '@hey-api/sdk',
549+
},
550+
],
551+
}),
552+
description: 'generates SDK functions with auth (OpenID Connect)',
553+
},
540554
{
541555
config: createConfig({
542556
input: 'security-oauth2.yaml',
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// This file is auto-generated by @hey-api/openapi-ts
2+
3+
import { createClient, createConfig } from '@hey-api/client-fetch';
4+
5+
export const client = createClient(createConfig());
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// This file is auto-generated by @hey-api/openapi-ts
2+
export * from './types.gen';
3+
export * from './sdk.gen';

0 commit comments

Comments
 (0)