From 6b2b92bee470c91b24fc30ce03b3fde09aaf15a9 Mon Sep 17 00:00:00 2001 From: Arman Date: Wed, 15 Jun 2022 14:09:38 +0200 Subject: [PATCH] feat: moved providers and auth methods to store --- src/routes/console/[project]/users/auth.ts | 598 ++++++++++++++++++ .../[project]/users/authentication.svelte | 297 +-------- 2 files changed, 608 insertions(+), 287 deletions(-) create mode 100644 src/routes/console/[project]/users/auth.ts diff --git a/src/routes/console/[project]/users/auth.ts b/src/routes/console/[project]/users/auth.ts new file mode 100644 index 000000000..20cbd9e3f --- /dev/null +++ b/src/routes/console/[project]/users/auth.ts @@ -0,0 +1,598 @@ +import { writable } from 'svelte/store'; +import type { Models } from 'src/sdk'; +import type { SvelteComponent } from 'svelte'; +import Apple from './_appleOAuth.svelte'; +import Microsoft from './_microsoftOAuth.svelte'; +import Okta from './_oktaOAuth.svelte'; +import Auth0 from './_auth0OAuth.svelte'; + +export type AuthMethod = { label: string; method: string; value: boolean }; +export type Provider = { + name: string; + icon: string; + active: boolean; + id: string | null; + secret: string | null; + docs?: string; + component?: typeof SvelteComponent; +}; + +export type Providers = { + providers: Provider[]; +}; + +function createAuthMethods() { + const { subscribe, set } = writable({ + list: [ + { + label: 'Password', + method: 'email-password', + value: null + }, + { + label: 'Magic URL', + method: 'magic-url', + value: null + }, + { + label: 'Anonymous', + method: 'anonymous', + value: null + }, + { + label: 'Invites', + method: 'invites', + value: null + }, + { + label: 'JWT', + method: 'jwt', + value: null + } + ] + }); + + return { + subscribe, + set, + load: (project: Models.Project) => { + const list = [ + { + label: 'Password', + method: 'email-password', + value: project.authEmailPassword + }, + { + label: 'Magic URL', + method: 'magic-url', + value: project.authUsersAuthMagicURL + }, + { + label: 'Anonymous', + method: 'anonymous', + value: project.authAnonymous + }, + { + label: 'Invites', + method: 'invites', + value: project.authInvites + }, + { + label: 'JWT', + method: 'jwt', + value: project.authJWT + } + ]; + set({ list }); + } + }; +} +function createOAuthProviders() { + const { subscribe, set } = writable({ + providers: [ + { + name: 'Amazon', + icon: 'amazon', + active: false, + id: null, + secret: null, + docs: 'https://developer.amazon.com/apps-and-games/services-and-apis' + }, + { + name: 'Apple', + icon: 'apple', + active: false, + id: null, + secret: null, + docs: 'https://developer.apple.com/', + component: Apple + }, + { + name: 'Auth0', + icon: 'auth0', + active: false, + id: null, + secret: null, + docs: 'https://auth0.com/developers', + component: Auth0 + }, + { + name: 'Bitbucket', + icon: 'bitBucket', + active: false, + id: null, + secret: null, + docs: 'https://developer.atlassian.com/bitbucket' + }, + { + name: 'Bitly', + icon: 'bitly', + active: false, + id: null, + secret: null, + docs: 'https://dev.bitly.com/v4_documentation.html' + }, + { + name: 'Box', + icon: 'box', + active: false, + id: null, + secret: null, + docs: 'https://developer.box.com/reference/' + }, + { + name: 'Discord', + icon: 'discord', + active: false, + id: null, + secret: null, + docs: 'https://discordapp.com/developers/docs/topics/oauth2' + }, + { + name: 'Dropbox', + icon: 'dropbox', + active: false, + id: null, + secret: null, + docs: 'https://www.dropbox.com/developers/documentation' + }, + { + name: 'Facebook', + icon: 'facebook', + active: false, + id: null, + secret: null, + docs: 'https://developers.facebook.com/' + }, + { + name: 'Github', + icon: 'github', + active: false, + id: null, + secret: null, + docs: 'https://developer.github.com/' + }, + { + name: 'Gitlab', + icon: 'gitlab', + active: false, + id: null, + secret: null, + docs: 'https://docs.gitlab.com/ee/api/' + }, + { + name: 'Google', + icon: 'google', + active: false, + id: null, + secret: null, + docs: 'https://support.google.com/googleapi/answer/6158849' + }, + { + name: 'Linkedin', + icon: 'linkedin', + active: false, + id: null, + secret: null, + docs: 'https://developer.linkedin.com/' + }, + { + name: 'Microsoft', + icon: 'microsoft', + active: false, + id: null, + secret: null, + docs: 'https://developer.microsoft.com/en-us/', + component: Microsoft + }, + { + name: 'Notion', + icon: 'notion', + active: false, + id: null, + secret: null, + docs: 'https://developers.notion.com/docs' + }, + { + name: 'Okta', + icon: 'okta', + active: false, + id: null, + secret: null, + docs: 'https://developer.okta.com/', + component: Okta + }, + { + name: 'Paypal', + icon: 'paypal', + active: false, + id: null, + secret: null, + docs: 'https://developer.paypal.com/docs/api/overview/' + }, + { + name: 'Paypal (sandbox)', + icon: 'paypal', + active: false, + id: null, + secret: null, + docs: 'https://developer.paypal.com/docs/api/overview/' + }, + { + name: 'Salesforce', + icon: 'salesforce', + active: false, + id: null, + secret: null, + docs: 'https://developer.salesforce.com/docs/' + }, + { + name: 'Slack', + icon: 'slack', + active: false, + id: null, + secret: null, + docs: 'https://api.slack.com/' + }, + { + name: 'Spotify', + icon: 'spotify', + active: false, + id: null, + secret: null, + docs: 'https://developer.spotify.com/documentation/general/guides/authorization-guide/' + }, + { + name: 'Stripe', + icon: 'stripe', + active: false, + id: null, + secret: null, + docs: 'https://stripe.com/docs/api' + }, + { + name: 'Tradeshift', + icon: 'tradeshift', + active: false, + id: null, + secret: null, + docs: 'https://developers.tradeshift.com/docs/api' + }, + { + name: 'Tradeshift(sandbox)', + icon: 'tradeshift', + active: false, + id: null, + secret: null, + docs: 'https://developers.tradeshift.com/docs/api' + }, + { + name: 'Twitch', + icon: 'twitch', + active: false, + id: null, + secret: null, + docs: 'https://dev.twitch.tv/docs/authentication' + }, + + { + name: 'Wordpress', + icon: 'wordpress', + active: false, + id: null, + secret: null, + docs: 'https://developer.wordpress.com/docs/oauth2/' + }, + { + name: 'Yahoo', + icon: 'yahoo', + active: false, + id: null, + secret: null, + docs: 'https://developer.yahoo.com/oauth2/guide/flows_authcode/' + }, + { + name: 'Yammer', + icon: 'ms_yammer', + active: false, + id: null, + secret: null, + docs: 'https://developer.yammer.com/docs/oauth-2' + }, + { + name: 'Yandex', + icon: 'yandex', + active: false, + id: null, + secret: null, + docs: 'https://tech.yandex.com/oauth/' + }, + { + name: 'Zoom', + icon: 'zoom', + active: false, + id: null, + secret: null, + docs: 'https://marketplace.zoom.us/docs/guides/auth/oauth/' + } + ] + }); + + return { + subscribe, + set, + load: (project: Models.Project) => { + const providers: Provider[] = [ + { + name: 'Amazon', + icon: 'amazon', + active: false, + id: project.providerAmazonAppid, + secret: project.providerAmazonSecret, + docs: 'https://developer.amazon.com/apps-and-games/services-and-apis' + }, + { + name: 'Apple', + icon: 'apple', + active: false, + id: project.providerAppleAppid, + secret: project.providerAppleSecret, + docs: 'https://developer.apple.com/', + component: Apple + }, + { + name: 'Auth0', + icon: 'auth0', + active: false, + id: project.providerAuth0Appid, + secret: project.providerAuth0Secret, + docs: 'https://auth0.com/developers', + component: Auth0 + }, + { + name: 'Bitbucket', + icon: 'bitBucket', + active: false, + id: project.providerBitbucketAppid, + secret: project.providerBitbucketSecret, + docs: 'https://developer.atlassian.com/bitbucket' + }, + { + name: 'Bitly', + icon: 'bitly', + active: false, + id: project.providerBitlyAppid, + secret: project.providerBitlySecret, + docs: 'https://dev.bitly.com/v4_documentation.html' + }, + { + name: 'Box', + icon: 'box', + active: false, + id: project.providerBoxAppid, + secret: project.providerBoxSecret, + docs: 'https://developer.box.com/reference/' + }, + { + name: 'Discord', + icon: 'discord', + active: false, + id: project.providerDiscordAppid, + secret: project.providerDiscordSecret, + docs: 'https://discordapp.com/developers/docs/topics/oauth2' + }, + { + name: 'Dropbox', + icon: 'dropbox', + active: false, + id: project.providerDropboxAppid, + secret: project.providerDropboxSecret, + docs: 'https://www.dropbox.com/developers/documentation' + }, + { + name: 'Facebook', + icon: 'facebook', + active: false, + id: project.providerFacebookAppid, + secret: project.providerFacebookSecret, + docs: 'https://developers.facebook.com/' + }, + { + name: 'Github', + icon: 'github', + active: false, + id: project.providerGithubAppid, + secret: project.providerGithubSecret, + docs: 'https://developer.github.com/' + }, + { + name: 'Gitlab', + icon: 'gitlab', + active: false, + id: project.providerGitlabAppid, + secret: project.providerGitlabSecret, + docs: 'https://docs.gitlab.com/ee/api/' + }, + { + name: 'Google', + icon: 'google', + active: false, + id: project.providerGoogleAppid, + secret: project.providerGoogleSecret, + docs: 'https://support.google.com/googleapi/answer/6158849' + }, + { + name: 'Linkedin', + icon: 'linkedin', + active: false, + id: project.providerLinkedinAppid, + secret: project.providerLinkedinSecret, + docs: 'https://developer.linkedin.com/' + }, + { + name: 'Microsoft', + icon: 'microsoft', + active: false, + id: project.providerMicrosoftAppid, + secret: project.providerMicrosoftSecret, + docs: 'https://developer.microsoft.com/en-us/', + component: Microsoft + }, + { + name: 'Notion', + icon: 'notion', + active: false, + id: project.providerNotionAppid, + secret: project.providerNotionSecret, + docs: 'https://developers.notion.com/docs' + }, + { + name: 'Okta', + icon: 'okta', + active: false, + id: project.providerOktaAppid, + secret: project.providerOktaSecret, + docs: 'https://developer.okta.com/', + component: Okta + }, + { + name: 'Paypal', + icon: 'paypal', + active: false, + id: project.providerPaypalAppid, + secret: project.providerPaypalSecret, + docs: 'https://developer.paypal.com/docs/api/overview/' + }, + { + name: 'Paypal (sandbox)', + icon: 'paypal', + active: false, + id: project.providerPaypalSandboxAppid, + secret: project.providerPaypalSandboxSecret, + docs: 'https://developer.paypal.com/docs/api/overview/' + }, + { + name: 'Salesforce', + icon: 'salesforce', + active: false, + id: project.providerSalesforceAppid, + secret: project.providerSalesforceSecret, + docs: 'https://developer.salesforce.com/docs/' + }, + { + name: 'Slack', + icon: 'slack', + active: false, + id: project.providerSlackAppid, + secret: project.providerSlackSecret, + docs: 'https://api.slack.com/' + }, + { + name: 'Spotify', + icon: 'spotify', + active: false, + id: project.providerSpotifyAppid, + secret: project.providerSpotifySecret, + docs: 'https://developer.spotify.com/documentation/general/guides/authorization-guide/' + }, + { + name: 'Stripe', + icon: 'stripe', + active: false, + id: project.providerStripeAppid, + secret: project.providerStripeSecret, + docs: 'https://stripe.com/docs/api' + }, + { + name: 'Tradeshift', + icon: 'tradeshift', + active: false, + id: project.providerTradeshiftAppid, + secret: project.providerTradeshiftSecret, + docs: 'https://developers.tradeshift.com/docs/api' + }, + { + name: 'Tradeshift(sandbox)', + icon: 'tradeshift', + active: false, + id: project.providerTradeshiftBoxAppid, + secret: project.providerTradeshiftBoxSecret, + docs: 'https://developers.tradeshift.com/docs/api' + }, + { + name: 'Twitch', + icon: 'twitch', + active: false, + id: project.providerTwitchAppid, + secret: project.providerTwitchSecret, + docs: 'https://dev.twitch.tv/docs/authentication' + }, + + { + name: 'Wordpress', + icon: 'wordpress', + active: false, + id: project.providerWordpressAppid, + secret: project.providerWordpressSecret, + docs: 'https://developer.wordpress.com/docs/oauth2/' + }, + { + name: 'Yahoo', + icon: 'yahoo', + active: false, + id: project.providerYahooAppid, + secret: project.providerYahooSecret, + docs: 'https://developer.yahoo.com/oauth2/guide/flows_authcode/' + }, + { + name: 'Yammer', + icon: 'ms_yammer', + active: false, + id: project.providerYammerAppid, + secret: project.providerYammerSecret, + docs: 'https://developer.yammer.com/docs/oauth-2' + }, + { + name: 'Yandex', + icon: 'yandex', + active: false, + id: project.providerYandexAppid, + secret: project.providerYandexSecret, + docs: 'https://tech.yandex.com/oauth/' + }, + { + name: 'Zoom', + icon: 'zoom', + active: false, + id: project.providerZoomAppid, + secret: project.providerZoomSecret, + docs: 'https://marketplace.zoom.us/docs/guides/auth/oauth/' + } + ]; + set({ providers }); + } + }; +} + +export const authMethods = createAuthMethods(); +export const OAuthProviders = createOAuthProviders(); diff --git a/src/routes/console/[project]/users/authentication.svelte b/src/routes/console/[project]/users/authentication.svelte index bd1bc0939..a6729783f 100644 --- a/src/routes/console/[project]/users/authentication.svelte +++ b/src/routes/console/[project]/users/authentication.svelte @@ -5,13 +5,13 @@ import { addNotification } from '$lib/stores/notifications'; import { sdkForConsole } from '$lib/stores/sdk'; import { project } from '../store'; + import { authMethods, OAuthProviders } from './auth'; + import type { Provider } from './auth'; import MainAuth from './_mainOAuth.svelte'; - import Apple from './_appleOAuth.svelte'; - import Microsoft from './_microsoftOAuth.svelte'; - import Okta from './_oktaOAuth.svelte'; - import Auth0 from './_auth0OAuth.svelte'; $: projectId = $project.$id; + $: authMethods.load($project); + $: OAuthProviders.load($project); let showModal = false; const authUpdate = async (id: string, value: boolean) => { @@ -29,285 +29,8 @@ } }; - let authBoxes = [ - { - label: 'Password', - id: 'email-password', - value: $project.authEmailPassword - }, - { - label: 'Magic URL', - id: 'magic-url', - value: $project.authUsersAuthMagicURL - }, - { - label: 'Anonymous', - id: 'anonymous', - value: $project.authAnonymous - }, - { - label: 'Invites', - id: 'invites', - value: $project.authInvites - }, - { - label: 'JWT', - id: 'jwt', - value: $project.authJWT - } - ]; + let selectedProvider: Provider | null = null; - let providers = [ - { - name: 'Amazon', - icon: 'amazon', - active: false, - id: $project.providerAmazonAppid, - secret: $project.providerAmazonSecret, - docs: 'https://developer.amazon.com/apps-and-games/services-and-apis' - }, - { - name: 'Apple', - icon: 'apple', - active: false, - id: $project.providerAppleAppid, - secret: $project.providerAppleSecret, - docs: 'https://developer.apple.com/', - component: Apple - }, - { - name: 'Auth0', - icon: 'auth0', - active: false, - id: $project.providerAuth0Appid, - secret: $project.providerAuth0Secret, - docs: 'https://auth0.com/developers', - component: Auth0 - }, - { - name: 'Bitbucket', - icon: 'bitBucket', - active: false, - id: $project.providerBitbucketAppid, - secret: $project.providerBitbucketSecret, - docs: 'https://developer.atlassian.com/bitbucket' - }, - { - name: 'Bitly', - icon: 'bitly', - active: false, - id: $project.providerBitlyAppid, - secret: $project.providerBitlySecret, - docs: 'https://dev.bitly.com/v4_documentation.html' - }, - { - name: 'Box', - icon: 'box', - active: false, - id: $project.providerBoxAppid, - secret: $project.providerBoxSecret, - docs: 'https://developer.box.com/reference/' - }, - { - name: 'Discord', - icon: 'discord', - active: false, - id: $project.providerDiscordAppid, - secret: $project.providerDiscordSecret, - docs: 'https://discordapp.com/developers/docs/topics/oauth2' - }, - { - name: 'Dropbox', - icon: 'dropbox', - active: false, - id: $project.providerDropboxAppid, - secret: $project.providerDropboxSecret, - docs: 'https://www.dropbox.com/developers/documentation' - }, - { - name: 'Facebook', - icon: 'facebook', - active: false, - id: $project.providerFacebookAppid, - secret: $project.providerFacebookSecret, - docs: 'https://developers.facebook.com/' - }, - { - name: 'Github', - icon: 'github', - active: false, - id: $project.providerGithubAppid, - secret: $project.providerGithubSecret, - docs: 'https://developer.github.com/' - }, - { - name: 'Gitlab', - icon: 'gitlab', - active: false, - id: $project.providerGitlabAppid, - secret: $project.providerGitlabSecret, - docs: 'https://docs.gitlab.com/ee/api/' - }, - { - name: 'Google', - icon: 'google', - active: false, - id: $project.providerGoogleAppid, - secret: $project.providerGoogleSecret, - docs: 'https://support.google.com/googleapi/answer/6158849' - }, - { - name: 'Linkedin', - icon: 'linkedin', - active: false, - id: $project.providerLinkedinAppid, - secret: $project.providerLinkedinSecret, - docs: 'https://developer.linkedin.com/' - }, - { - name: 'Microsoft', - icon: 'microsoft', - active: false, - id: $project.providerMicrosoftAppid, - secret: $project.providerMicrosoftSecret, - docs: 'https://developer.microsoft.com/en-us/', - component: Microsoft - }, - { - name: 'Notion', - icon: 'notion', - active: false, - id: $project.providerNotionAppid, - secret: $project.providerNotionSecret, - docs: 'https://developers.notion.com/docs' - }, - { - name: 'Okta', - icon: 'okta', - active: false, - id: $project.providerOktaAppid, - secret: $project.providerOktaSecret, - docs: 'https://developer.okta.com/', - component: Okta - }, - { - name: 'Paypal', - icon: 'paypal', - active: false, - id: $project.providerPaypalAppid, - secret: $project.providerPaypalSecret, - docs: 'https://developer.paypal.com/docs/api/overview/' - }, - { - name: 'Paypal (sandbox)', - icon: 'paypal', - active: false, - id: $project.providerPaypalSandboxAppid, - secret: $project.providerPaypalSandboxSecret, - docs: 'https://developer.paypal.com/docs/api/overview/' - }, - { - name: 'Salesforce', - icon: 'salesforce', - active: false, - id: $project.providerSalesforceAppid, - secret: $project.providerSalesforceSecret, - docs: 'https://developer.salesforce.com/docs/' - }, - { - name: 'Slack', - icon: 'slack', - active: false, - id: $project.providerSlackAppid, - secret: $project.providerSlackSecret, - docs: 'https://api.slack.com/' - }, - { - name: 'Spotify', - icon: 'spotify', - active: false, - id: $project.providerSpotifyAppid, - secret: $project.providerSpotifySecret, - docs: 'https://developer.spotify.com/documentation/general/guides/authorization-guide/' - }, - { - name: 'Stripe', - icon: 'stripe', - active: false, - id: $project.providerStripeAppid, - secret: $project.providerStripeSecret, - docs: 'https://stripe.com/docs/api' - }, - { - name: 'Tradeshift', - icon: 'tradeshift', - active: false, - id: $project.providerTradeshiftAppid, - secret: $project.providerTradeshiftSecret, - docs: 'https://developers.tradeshift.com/docs/api' - }, - { - name: 'Tradeshift(sandbox)', - icon: 'tradeshift', - active: false, - id: $project.providerTradeshiftBoxAppid, - secret: $project.providerTradeshiftBoxSecret, - docs: 'https://developers.tradeshift.com/docs/api' - }, - { - name: 'Twitch', - icon: 'twitch', - active: false, - id: $project.providerTwitchAppid, - secret: $project.providerTwitchSecret, - docs: 'https://dev.twitch.tv/docs/authentication' - }, - - { - name: 'Wordpress', - icon: 'wordpress', - active: false, - id: $project.providerWordpressAppid, - secret: $project.providerWordpressSecret, - docs: 'https://developer.wordpress.com/docs/oauth2/' - }, - { - name: 'Yahoo', - icon: 'yahoo', - active: false, - id: $project.providerYahooAppid, - secret: $project.providerYahooSecret, - docs: 'https://developer.yahoo.com/oauth2/guide/flows_authcode/' - }, - { - name: 'Yammer', - icon: 'ms_yammer', - active: false, - id: $project.providerYammerAppid, - secret: $project.providerYammerSecret, - docs: 'https://developer.yammer.com/docs/oauth-2' - }, - { - name: 'Yandex', - icon: 'yandex', - active: false, - id: $project.providerYandexAppid, - secret: $project.providerYandexSecret, - docs: 'https://tech.yandex.com/oauth/' - }, - { - name: 'Zoom', - icon: 'zoom', - active: false, - id: $project.providerZoomAppid, - secret: $project.providerZoomSecret, - docs: 'https://marketplace.zoom.us/docs/guides/auth/oauth/' - } - ]; - - let selectedProvider: typeof providers[0]; - - //TODO: move authBoxes and providers to a store //TODO: if operation not successful revert switchbox value @@ -318,19 +41,19 @@

Enable the auth methods you wish to use.