From a0cc87c96cab08693481b3fcf44e68a8cbfbb9e9 Mon Sep 17 00:00:00 2001 From: Malte Teichert Date: Mon, 20 May 2024 18:38:22 +0200 Subject: [PATCH] re-add authentication section --- src/app.d.ts | 15 ++ src/lib/authTemplates.ts | 74 ++---- .../atoms/AuthenticationItem.svelte | 230 ++++++++---------- src/lib/components/atoms/OAuthFlow.svelte | 132 +++++----- .../components/sections/Authentication.svelte | 49 ++-- src/routes/+page.svelte | 2 +- 6 files changed, 234 insertions(+), 268 deletions(-) diff --git a/src/app.d.ts b/src/app.d.ts index 8f4d638..296b72f 100644 --- a/src/app.d.ts +++ b/src/app.d.ts @@ -7,3 +7,18 @@ declare namespace App { // interface Error {} // interface Platform {} } + +declare namespace Oauth2 { + interface Oauth2Flow { + authorizationUrl: string; + scopes: Record; + refreshUrl?: string; + } + + interface Oauth2FlowTemplates { + implicit: Oauth2Flow; + password: Oauth2Flow; + clientCredentials: Oauth2Flow; + authorizationCode: Oauth2Flow & { tokenUrl: string }; + } +} diff --git a/src/lib/authTemplates.ts b/src/lib/authTemplates.ts index e839010..1911fc9 100644 --- a/src/lib/authTemplates.ts +++ b/src/lib/authTemplates.ts @@ -1,71 +1,49 @@ -import type { - ApiKeyAuth, - BasicAuth, - BearerAuth, - CookieAuth, - OAuth2Auth, - OpenIdConnectAuth -} from './types/auth'; +import type { OpenAPIV3_1 } from './openAPITypes'; -export const basicAuthTemplate: BasicAuth = { - identifier: '', +export const basicAuthTemplate: OpenAPIV3_1.HttpSecurityScheme = { type: 'http', - scheme: 'basic' + scheme: 'basic', + description: undefined }; -export const bearerAuthTemplate: BearerAuth = { - identifier: '', +export const bearerAuthTemplate: OpenAPIV3_1.HttpSecurityScheme = { type: 'http', scheme: 'bearer', - bearerFormat: '' + bearerFormat: undefined, + description: undefined }; -export const apiKeyAuthTemplate: ApiKeyAuth = { - identifier: '', +export const apiKeyAuthTemplate: OpenAPIV3_1.ApiKeySecurityScheme = { type: 'apiKey', - in: 'header', - name: '' + in: 'header', // or 'query' or 'cookie' + name: '', + description: undefined }; -export const openIdAuthTemplate: OpenIdConnectAuth = { - identifier: '', +export const openIdAuthTemplate: OpenAPIV3_1.OpenIdSecurityScheme = { type: 'openIdConnect', - openIdConnectUrl: '' + openIdConnectUrl: '', + description: undefined }; -export const oauth2AuthTemplate: OAuth2Auth = { - identifier: '', +export const oauth2AuthTemplate: OpenAPIV3_1.OAuth2SecurityScheme = { type: 'oauth2', - description: '', - flows: [] + flows: {}, + description: undefined }; -export const cookieAuthTemplate: CookieAuth = { - identifier: '', - type: 'apiKey', - in: 'cookie', - name: '' +const baseOauth2Flow: Oauth2.Oauth2Flow = { + authorizationUrl: '', + scopes: {}, + refreshUrl: undefined }; -export const oauth2FlowTemplates = { +export const oauth2FlowTemplates: Oauth2.Oauth2FlowTemplates = { + implicit: baseOauth2Flow, + password: baseOauth2Flow, + clientCredentials: baseOauth2Flow, authorizationCode: { - name: 'authorizationCode', - authorizationUrl: '', - tokenUrl: '', - scopes: [] - }, - implicit: { - name: 'implicit', - authorizationUrl: '', - scopes: [] - }, - password: { - name: 'password', - tokenUrl: '', - scopes: [] - }, - clientCredentials: { - name: 'clientCredentials', + ...baseOauth2Flow, tokenUrl: '' } }; diff --git a/src/lib/components/atoms/AuthenticationItem.svelte b/src/lib/components/atoms/AuthenticationItem.svelte index 119dac6..7ac6bad 100644 --- a/src/lib/components/atoms/AuthenticationItem.svelte +++ b/src/lib/components/atoms/AuthenticationItem.svelte @@ -1,169 +1,129 @@ -
-
- {#if data.type == 'http' && data.scheme == 'basic'} -

Basic Auth

-

Basic authentication is a simple authentication scheme built into the HTTP protocol.

- - {:else if data.type == 'http' && data.scheme == 'bearer'} -

Bearer Auth

-

Basic authentication is a simple authentication scheme built into the HTTP protocol.

- - - {:else if data.type == 'apiKey' && data.in == 'header'} - -

API Key

+
+ {#if schema.type === 'http' && schema.scheme === 'basic'} +

Basic Authentication

- API keys are a simple authentication method that the client provides when making API requests. + Basic authentication is a simple authentication scheme built into the HTTP protocol. No + configuration required.

- - - - {:else if data.type == 'openIdConnect'} -

OpenID

+ {:else if schema.type === 'http' && schema.scheme === 'bearer'} +

Bearer Authentication

- OpenID Connect (OIDC) is an identity layer built on top of the OAuth 2.0 protocol and - supported by some OAuth 2.0 providers, such as Google and Azure Active Directory. + Bearer authentication (also called token authentication) is an HTTP authentication scheme that + involves security tokens called bearer tokens.

-