mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-21 18:13:29 +00:00
Improve support for OAuth2 security type (#3304)
This commit is contained in:
@@ -0,0 +1,6 @@
|
|||||||
|
---
|
||||||
|
'@gitbook/react-openapi': patch
|
||||||
|
'gitbook': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Improve support for OAuth2 security type
|
||||||
@@ -310,6 +310,26 @@
|
|||||||
@apply py-2 border-b border-tint-subtle max-w-full flex-1;
|
@apply py-2 border-b border-tint-subtle max-w-full flex-1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.openapi-securities-oauth-flows {
|
||||||
|
@apply flex flex-col gap-2 divide-y divide-tint-subtle;
|
||||||
|
}
|
||||||
|
|
||||||
|
.openapi-securities-oauth-content {
|
||||||
|
@apply prose *:!prose-sm *:text-tint;
|
||||||
|
}
|
||||||
|
|
||||||
|
.openapi-securities-oauth-content.openapi-markdown code {
|
||||||
|
@apply text-xs;
|
||||||
|
}
|
||||||
|
|
||||||
|
.openapi-securities-oauth-content ul {
|
||||||
|
@apply !my-0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.openapi-securities-url {
|
||||||
|
@apply ml-0.5 px-0.5 rounded hover:bg-tint transition-colors;
|
||||||
|
}
|
||||||
|
|
||||||
.openapi-securities-body {
|
.openapi-securities-body {
|
||||||
@apply flex flex-col gap-2;
|
@apply flex flex-col gap-2;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,12 +27,14 @@ export function OpenAPISchemaName(props: OpenAPISchemaNameProps) {
|
|||||||
{propertyName}
|
{propertyName}
|
||||||
</span>
|
</span>
|
||||||
) : null}
|
) : null}
|
||||||
|
{type || additionalItems ? (
|
||||||
<span>
|
<span>
|
||||||
{type ? <span className="openapi-schema-type">{type}</span> : null}
|
{type ? <span className="openapi-schema-type">{type}</span> : null}
|
||||||
{additionalItems ? (
|
{additionalItems ? (
|
||||||
<span className="openapi-schema-type">{additionalItems}</span>
|
<span className="openapi-schema-type">{additionalItems}</span>
|
||||||
) : null}
|
) : null}
|
||||||
</span>
|
</span>
|
||||||
|
) : null}
|
||||||
{schema?.readOnly ? (
|
{schema?.readOnly ? (
|
||||||
<span className="openapi-schema-readonly">
|
<span className="openapi-schema-readonly">
|
||||||
{t(context.translation, 'read_only')}
|
{t(context.translation, 'read_only')}
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
|
import type { OpenAPIV3 } from '@gitbook/openapi-parser';
|
||||||
import { InteractiveSection } from './InteractiveSection';
|
import { InteractiveSection } from './InteractiveSection';
|
||||||
import { Markdown } from './Markdown';
|
import { Markdown } from './Markdown';
|
||||||
|
import { OpenAPICopyButton } from './OpenAPICopyButton';
|
||||||
import { OpenAPISchemaName } from './OpenAPISchemaName';
|
import { OpenAPISchemaName } from './OpenAPISchemaName';
|
||||||
import type { OpenAPIClientContext } from './context';
|
import type { OpenAPIClientContext } from './context';
|
||||||
import { t } from './translate';
|
import { t } from './translate';
|
||||||
@@ -105,13 +107,7 @@ function getLabelForType(security: OpenAPISecurityWithRequired, context: OpenAPI
|
|||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
case 'oauth2':
|
case 'oauth2':
|
||||||
return (
|
return <OpenAPISchemaOAuth2Flows context={context} security={security} />;
|
||||||
<OpenAPISchemaName
|
|
||||||
context={context}
|
|
||||||
propertyName="OAuth2"
|
|
||||||
required={security.required}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
case 'openIdConnect':
|
case 'openIdConnect':
|
||||||
return (
|
return (
|
||||||
<OpenAPISchemaName
|
<OpenAPISchemaName
|
||||||
@@ -125,3 +121,111 @@ function getLabelForType(security: OpenAPISecurityWithRequired, context: OpenAPI
|
|||||||
return security.type;
|
return security.type;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function OpenAPISchemaOAuth2Flows(props: {
|
||||||
|
context: OpenAPIClientContext;
|
||||||
|
security: OpenAPIV3.OAuth2SecurityScheme & { required?: boolean };
|
||||||
|
}) {
|
||||||
|
const { context, security } = props;
|
||||||
|
|
||||||
|
const flows = Object.entries(security.flows ?? {});
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="openapi-securities-oauth-flows">
|
||||||
|
{flows.map(([name, flow], index) => (
|
||||||
|
<OpenAPISchemaOAuth2Item
|
||||||
|
key={index}
|
||||||
|
flow={flow}
|
||||||
|
name={name}
|
||||||
|
context={context}
|
||||||
|
security={security}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function OpenAPISchemaOAuth2Item(props: {
|
||||||
|
flow: NonNullable<OpenAPIV3.OAuth2SecurityScheme['flows']>[keyof NonNullable<
|
||||||
|
OpenAPIV3.OAuth2SecurityScheme['flows']
|
||||||
|
>];
|
||||||
|
name: string;
|
||||||
|
context: OpenAPIClientContext;
|
||||||
|
security: OpenAPIV3.OAuth2SecurityScheme & { required?: boolean };
|
||||||
|
}) {
|
||||||
|
const { flow, context, security, name } = props;
|
||||||
|
|
||||||
|
if (!flow) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const scopes = Object.entries(flow?.scopes ?? {});
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<OpenAPISchemaName
|
||||||
|
context={context}
|
||||||
|
propertyName="OAuth2"
|
||||||
|
type={name}
|
||||||
|
required={security.required}
|
||||||
|
/>
|
||||||
|
<div className="openapi-securities-oauth-content openapi-markdown">
|
||||||
|
{security.description ? <Markdown source={security.description} /> : null}
|
||||||
|
{'authorizationUrl' in flow && flow.authorizationUrl ? (
|
||||||
|
<span>
|
||||||
|
Authorization URL:{' '}
|
||||||
|
<OpenAPICopyButton
|
||||||
|
value={flow.authorizationUrl}
|
||||||
|
context={context}
|
||||||
|
className="openapi-securities-url"
|
||||||
|
withTooltip
|
||||||
|
>
|
||||||
|
{flow.authorizationUrl}
|
||||||
|
</OpenAPICopyButton>
|
||||||
|
</span>
|
||||||
|
) : null}
|
||||||
|
{'tokenUrl' in flow && flow.tokenUrl ? (
|
||||||
|
<span>
|
||||||
|
Token URL:{' '}
|
||||||
|
<OpenAPICopyButton
|
||||||
|
value={flow.tokenUrl}
|
||||||
|
context={context}
|
||||||
|
className="openapi-securities-url"
|
||||||
|
withTooltip
|
||||||
|
>
|
||||||
|
{flow.tokenUrl}
|
||||||
|
</OpenAPICopyButton>
|
||||||
|
</span>
|
||||||
|
) : null}
|
||||||
|
{'refreshUrl' in flow && flow.refreshUrl ? (
|
||||||
|
<span>
|
||||||
|
Refresh URL:{' '}
|
||||||
|
<OpenAPICopyButton
|
||||||
|
value={flow.refreshUrl}
|
||||||
|
context={context}
|
||||||
|
className="openapi-securities-url"
|
||||||
|
withTooltip
|
||||||
|
>
|
||||||
|
{flow.refreshUrl}
|
||||||
|
</OpenAPICopyButton>
|
||||||
|
</span>
|
||||||
|
) : null}
|
||||||
|
{scopes.length ? (
|
||||||
|
<div>
|
||||||
|
{t(context.translation, 'available_scopes')}:{' '}
|
||||||
|
<ul>
|
||||||
|
{scopes.map(([key, value]) => (
|
||||||
|
<li key={key}>
|
||||||
|
<OpenAPICopyButton value={key} context={context} withTooltip>
|
||||||
|
<code>{key}</code>
|
||||||
|
</OpenAPICopyButton>
|
||||||
|
: {value}
|
||||||
|
</li>
|
||||||
|
))}
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
) : null}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ export const de = {
|
|||||||
show: 'Zeige ${1}',
|
show: 'Zeige ${1}',
|
||||||
hide: 'Verstecke ${1}',
|
hide: 'Verstecke ${1}',
|
||||||
available_items: 'Verfügbare Elemente',
|
available_items: 'Verfügbare Elemente',
|
||||||
|
available_scopes: 'Verfügbare scopes',
|
||||||
properties: 'Eigenschaften',
|
properties: 'Eigenschaften',
|
||||||
or: 'oder',
|
or: 'oder',
|
||||||
and: 'und',
|
and: 'und',
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ export const en = {
|
|||||||
show: 'Show ${1}',
|
show: 'Show ${1}',
|
||||||
hide: 'Hide ${1}',
|
hide: 'Hide ${1}',
|
||||||
available_items: 'Available items',
|
available_items: 'Available items',
|
||||||
|
available_scopes: 'Available scopes',
|
||||||
possible_values: 'Possible values',
|
possible_values: 'Possible values',
|
||||||
properties: 'Properties',
|
properties: 'Properties',
|
||||||
or: 'or',
|
or: 'or',
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ export const es = {
|
|||||||
show: 'Mostrar ${1}',
|
show: 'Mostrar ${1}',
|
||||||
hide: 'Ocultar ${1}',
|
hide: 'Ocultar ${1}',
|
||||||
available_items: 'Elementos disponibles',
|
available_items: 'Elementos disponibles',
|
||||||
|
available_scopes: 'Scopes disponibles',
|
||||||
properties: 'Propiedades',
|
properties: 'Propiedades',
|
||||||
or: 'o',
|
or: 'o',
|
||||||
and: 'y',
|
and: 'y',
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ export const fr = {
|
|||||||
show: 'Afficher ${1}',
|
show: 'Afficher ${1}',
|
||||||
hide: 'Masquer ${1}',
|
hide: 'Masquer ${1}',
|
||||||
available_items: 'Éléments disponibles',
|
available_items: 'Éléments disponibles',
|
||||||
|
available_scopes: 'Scopes disponibles',
|
||||||
properties: 'Propriétés',
|
properties: 'Propriétés',
|
||||||
or: 'ou',
|
or: 'ou',
|
||||||
and: 'et',
|
and: 'et',
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ export const ja = {
|
|||||||
show: '${1}を表示',
|
show: '${1}を表示',
|
||||||
hide: '${1}を非表示',
|
hide: '${1}を非表示',
|
||||||
available_items: '利用可能なアイテム',
|
available_items: '利用可能なアイテム',
|
||||||
|
available_scopes: '利用可能なスコープ',
|
||||||
properties: 'プロパティ',
|
properties: 'プロパティ',
|
||||||
or: 'または',
|
or: 'または',
|
||||||
and: 'かつ',
|
and: 'かつ',
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ export const nl = {
|
|||||||
show: 'Toon ${1}',
|
show: 'Toon ${1}',
|
||||||
hide: 'Verberg ${1}',
|
hide: 'Verberg ${1}',
|
||||||
available_items: 'Beschikbare items',
|
available_items: 'Beschikbare items',
|
||||||
|
available_scopes: 'Beschikbare scopes',
|
||||||
properties: 'Eigenschappen',
|
properties: 'Eigenschappen',
|
||||||
or: 'of',
|
or: 'of',
|
||||||
and: 'en',
|
and: 'en',
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ export const no = {
|
|||||||
show: 'Vis ${1}',
|
show: 'Vis ${1}',
|
||||||
hide: 'Skjul ${1}',
|
hide: 'Skjul ${1}',
|
||||||
available_items: 'Tilgjengelige elementer',
|
available_items: 'Tilgjengelige elementer',
|
||||||
|
available_scopes: 'Tilgjengelige scopes',
|
||||||
properties: 'Egenskaper',
|
properties: 'Egenskaper',
|
||||||
or: 'eller',
|
or: 'eller',
|
||||||
and: 'og',
|
and: 'og',
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ export const pt_br = {
|
|||||||
show: 'Mostrar ${1}',
|
show: 'Mostrar ${1}',
|
||||||
hide: 'Ocultar ${1}',
|
hide: 'Ocultar ${1}',
|
||||||
available_items: 'Itens disponíveis',
|
available_items: 'Itens disponíveis',
|
||||||
|
available_scopes: 'Scopes disponíveis',
|
||||||
properties: 'Propriedades',
|
properties: 'Propriedades',
|
||||||
or: 'ou',
|
or: 'ou',
|
||||||
and: 'e',
|
and: 'e',
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ export const zh = {
|
|||||||
show: '显示${1}',
|
show: '显示${1}',
|
||||||
hide: '隐藏${1}',
|
hide: '隐藏${1}',
|
||||||
available_items: '可用项',
|
available_items: '可用项',
|
||||||
|
available_scopes: '可用范围',
|
||||||
properties: '属性',
|
properties: '属性',
|
||||||
or: '或',
|
or: '或',
|
||||||
and: '和',
|
and: '和',
|
||||||
|
|||||||
Reference in New Issue
Block a user