Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

fix: make Apple OAuth client secret optional for native sign-in (#44386)

Cemal Kılıç92692240bf8b
diff --git a/apps/studio/components/interfaces/Auth/AuthProvidersFormValidation.tsx b/apps/studio/components/interfaces/Auth/AuthProvidersFormValidation.tsx
index 752550df206..ab9cb817118 100644
--- a/apps/studio/components/interfaces/Auth/AuthProvidersFormValidation.tsx
+++ b/apps/studio/components/interfaces/Auth/AuthProvidersFormValidation.tsx
@@ -472,69 +472,56 @@ const EXTERNAL_PROVIDER_APPLE = {
},
validationSchema: object().shape({
EXTERNAL_APPLE_ENABLED: boolean().required(),
- EXTERNAL_APPLE_SECRET: string()
- .when(['EXTERNAL_APPLE_ENABLED', 'EXTERNAL_APPLE_CLIENT_ID'], {
- is: (EXTERNAL_APPLE_ENABLED: boolean, EXTERNAL_APPLE_CLIENT_ID: string) => {
- return EXTERNAL_APPLE_ENABLED && !!EXTERNAL_APPLE_CLIENT_ID
- },
- then: (schema) =>
- schema
- .matches(/^[a-z0-9_-]+([.][a-z0-9_-]+){2}$/i, 'Secret key should be a JWT.')
- .test({
- message: 'Secret key is not a correctly generated JWT.',
- test: (value?: string): boolean => {
- if (!value) {
- return true
- }
- try {
- const parts = value.split('.').map((value) => parseBase64URL(value))
- const header = JSON.parse(parts[0])
- const body = JSON.parse(parts[1])
- return (
- typeof header === 'object' &&
- typeof body === 'object' &&
- header &&
- body &&
- header.alg === 'ES256' &&
- body.aud === 'https://appleid.apple.com'
- )
- } catch (e: any) {
- console.log(e)
- return false
- }
-
+ EXTERNAL_APPLE_SECRET: string().when('EXTERNAL_APPLE_ENABLED', {
+ is: true,
+ then: (schema) =>
+ schema
+ .matches(/^([a-z0-9_-]+([.][a-z0-9_-]+){2})?$/i, 'Secret key should be a JWT.')
+ .test({
+ message: 'Secret key is not a correctly generated JWT.',
+ test: (value?: string): boolean => {
+ if (!value) {
return true
- },
- })
- .test({
- message: 'Secret key expires in less than 7 days!',
- test: (value?: string) => {
- if (!value) {
- return true
- }
- try {
- const parts = value.split('.').map((value) => parseBase64URL(value))
- const body = JSON.parse(parts[1])
- return Date.now() > body.exp - 7 * 24 * 60 * 60 * 1000
- } catch (e: any) {
- console.log(e)
- return false
- }
+ }
+ try {
+ const parts = value.split('.').map((value) => parseBase64URL(value))
+ const header = JSON.parse(parts[0])
+ const body = JSON.parse(parts[1])
+ return (
+ typeof header === 'object' &&
+ typeof body === 'object' &&
+ header &&
+ body &&
+ header.alg === 'ES256' &&
+ body.aud === 'https://appleid.apple.com'
+ )
+ } catch (e: any) {
+ console.log(e)
+ return false
+ }
+ return true
+ },
+ })
+ .test({
+ message: 'Secret key expires in less than 7 days!',
+ test: (value?: string) => {
+ if (!value) {
return true
- },
- }),
- })
- .when(['EXTERNAL_APPLE_ENABLED', 'EXTERNAL_APPLE_CLIENT_ID'], {
- is: (EXTERNAL_APPLE_ENABLED: boolean, EXTERNAL_APPLE_CLIENT_ID: string) => {
- return EXTERNAL_APPLE_ENABLED && !EXTERNAL_APPLE_CLIENT_ID
- },
- then: (schema) =>
- schema.matches(
- /^$/,
- 'Secret Key should only be set if Service ID for OAuth is provided.'
- ),
- }),
+ }
+ try {
+ const parts = value.split('.').map((value) => parseBase64URL(value))
+ const body = JSON.parse(parts[1])
+ return Date.now() > body.exp - 7 * 24 * 60 * 60 * 1000
+ } catch (e: any) {
+ console.log(e)
+ return false
+ }
+
+ return true
+ },
+ }),
+ }),
EXTERNAL_APPLE_CLIENT_ID: string()
.matches(/^\S+$/, 'Client IDs should not contain spaces.')
.matches(