fix: make client credential optional in authcode + pkce flow (#4114)

* fix: make client credential optional

* test: update test fixtures

---------

Co-authored-by: jamesgeorge007 <25279263+jamesgeorge007@users.noreply.github.com>
This commit is contained in:
Akash K
2024-06-12 14:10:54 +05:30
committed by GitHub
parent e3ad0c9e2e
commit 93807bfe8f
7 changed files with 140 additions and 20 deletions

View File

@@ -4,6 +4,7 @@ import V1_VERSION from "./v/1"
import V2_VERSION from "./v/2"
import V3_VERSION from "./v/3"
import V4_VERSION from "./v/4"
import V5_VERSION from "./v/5"
export { GQLHeader } from "./v/1"
export {
@@ -13,23 +14,24 @@ export {
HoppGQLAuthInherit,
} from "./v/2"
export { HoppGQLAuth } from "./v/4"
export { HoppGQLAuthOAuth2 } from "./v/3"
export { HoppGQLAuthOAuth2, HoppGQLAuth } from "./v/5"
export { HoppGQLAuthAPIKey } from "./v/4"
export const GQL_REQ_SCHEMA_VERSION = 4
export const GQL_REQ_SCHEMA_VERSION = 5
const versionedObject = z.object({
v: z.number(),
})
export const HoppGQLRequest = createVersionedEntity({
latestVersion: 4,
latestVersion: 5,
versionMap: {
1: V1_VERSION,
2: V2_VERSION,
3: V3_VERSION,
4: V4_VERSION,
5: V5_VERSION,
},
getVersion(x) {
const result = versionedObject.safeParse(x)

View File

@@ -0,0 +1,47 @@
import { z } from "zod"
import { defineVersion } from "verzod"
import { HoppRESTAuthOAuth2 } from "../../rest/v/5"
import {
HoppGQLAuthBasic,
HoppGQLAuthBearer,
HoppGQLAuthInherit,
HoppGQLAuthNone,
} from "./2"
import { HoppGQLAuthAPIKey, V4_SCHEMA } from "./4"
export { HoppRESTAuthOAuth2 as HoppGQLAuthOAuth2 } from "../../rest/v/5"
export const HoppGQLAuth = z
.discriminatedUnion("authType", [
HoppGQLAuthNone,
HoppGQLAuthInherit,
HoppGQLAuthBasic,
HoppGQLAuthBearer,
HoppGQLAuthAPIKey,
HoppRESTAuthOAuth2, // both rest and gql have the same auth type for oauth2
])
.and(
z.object({
authActive: z.boolean(),
})
)
export type HoppGQLAuth = z.infer<typeof HoppGQLAuth>
export const V5_SCHEMA = V4_SCHEMA.extend({
v: z.literal(5),
auth: HoppGQLAuth,
})
export default defineVersion({
initial: false,
schema: V5_SCHEMA,
up(old: z.infer<typeof V4_SCHEMA>) {
return {
...old,
v: 5 as const,
}
},
})