From 4d1b1c4a3e08f2c8b67e0ca07fc6225bb66cbc77 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 27 Sep 2023 09:19:02 +1000 Subject: [PATCH 1/5] Add Apple Login --- package-lock.json | 21 +++++++++++++++++++ package.json | 1 + .../components/SignInProviders.tsx | 3 +++ 3 files changed, 25 insertions(+) diff --git a/package-lock.json b/package-lock.json index 6f5fe7b3d..bb51986dd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -35,6 +35,7 @@ "lodash": "^4.17.21", "pretty-bytes": "^6.0.0", "react": "^18.2.0", + "react-apple-login": "^1.1.6", "react-colorful": "^5.6.1", "react-date-range": "^1.4.0", "react-datepicker": "^4.11.0", @@ -10951,6 +10952,20 @@ "node": ">=0.10.0" } }, + "node_modules/react-apple-login": { + "version": "1.1.6", + "resolved": "https://registry.npmjs.org/react-apple-login/-/react-apple-login-1.1.6.tgz", + "integrity": "sha512-ySV6ax0aB+ksA7lKzhr4MvsgjwSH068VtdHJXS+7rL380IJnNQNl14SszR31k3UqB8q8C1H1oyjJFGq4MyO6tw==", + "engines": { + "node": ">=8", + "npm": ">=5" + }, + "peerDependencies": { + "prop-types": "^15.5.4", + "react": "^15.0.0 || ^16.0.0 || ^17.0.0 || ^18.0.0", + "react-dom": "^15.0.0 || ^16.0.0 || ^17.0.0 || ^18.0.0" + } + }, "node_modules/react-base16-styling": { "version": "0.9.1", "resolved": "https://registry.npmjs.org/react-base16-styling/-/react-base16-styling-0.9.1.tgz", @@ -20837,6 +20852,12 @@ "loose-envify": "^1.1.0" } }, + "react-apple-login": { + "version": "1.1.6", + "resolved": "https://registry.npmjs.org/react-apple-login/-/react-apple-login-1.1.6.tgz", + "integrity": "sha512-ySV6ax0aB+ksA7lKzhr4MvsgjwSH068VtdHJXS+7rL380IJnNQNl14SszR31k3UqB8q8C1H1oyjJFGq4MyO6tw==", + "requires": {} + }, "react-base16-styling": { "version": "0.9.1", "resolved": "https://registry.npmjs.org/react-base16-styling/-/react-base16-styling-0.9.1.tgz", diff --git a/package.json b/package.json index c372c5f6e..9b47f7333 100644 --- a/package.json +++ b/package.json @@ -30,6 +30,7 @@ "lodash": "^4.17.21", "pretty-bytes": "^6.0.0", "react": "^18.2.0", + "react-apple-login": "^1.1.6", "react-colorful": "^5.6.1", "react-date-range": "^1.4.0", "react-datepicker": "^4.11.0", diff --git a/src/pages/authentication/components/SignInProviders.tsx b/src/pages/authentication/components/SignInProviders.tsx index 7570da855..726a5af18 100644 --- a/src/pages/authentication/components/SignInProviders.tsx +++ b/src/pages/authentication/components/SignInProviders.tsx @@ -23,6 +23,7 @@ import { ReactNode } from 'react'; import { GoogleLogin } from '@react-oauth/google'; import { toast } from '$app/common/helpers/toast/toast'; import { PublicClientApplication } from '@azure/msal-browser'; +import AppleLogin from 'react-apple-login'; export const msal = new PublicClientApplication({ auth: { @@ -134,6 +135,8 @@ export function SignInProviders() {

Log in with Microsoft

+ + {/* eslint-disable-next-line @typescript-eslint/ban-ts-comment From 26c35856ee2cc20d8a5aeb078539c22a63e4fe75 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 27 Sep 2023 09:32:47 +1000 Subject: [PATCH 2/5] Add Apple Login --- .../components/SignInProviders.tsx | 36 ++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/src/pages/authentication/components/SignInProviders.tsx b/src/pages/authentication/components/SignInProviders.tsx index 726a5af18..e6c9f362b 100644 --- a/src/pages/authentication/components/SignInProviders.tsx +++ b/src/pages/authentication/components/SignInProviders.tsx @@ -24,6 +24,7 @@ import { GoogleLogin } from '@react-oauth/google'; import { toast } from '$app/common/helpers/toast/toast'; import { PublicClientApplication } from '@azure/msal-browser'; import AppleLogin from 'react-apple-login'; +import { v4 } from 'uuid'; export const msal = new PublicClientApplication({ auth: { @@ -92,6 +93,12 @@ export function SignInProviders() { ).then((response) => login(response)); }; + const handleApple = (response: any) => { + request('POST', endpoint('/api/v1/oauth_login?provider=apple'), { + id_token: response.authorization.id_token, + }).then((response) => login(response)); + } + const handleMicrosoft = (token: string) => { request('POST', endpoint('/api/v1/oauth_login?provider=microsoft'), { accessToken: token, @@ -135,7 +142,34 @@ export function SignInProviders() {

Log in with Microsoft

- + {handleApple(response)}} + /> + +{/* +payload should look like this. +{ + "authorization": { + "state": "[STATE]", + "code": "[CODE]", + "id_token": "[ID_TOKEN]" + }, + "user": { + "email": "[EMAIL]", + "name": { + "firstName": "[FIRST_NAME]", + "lastName": "[LAST_NAME]" + } + } +} */} + {/* eslint-disable-next-line From ae8d8fe32c26e414916517517693231af08c6eee Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 27 Sep 2023 10:00:00 +1000 Subject: [PATCH 3/5] Add Apple Login --- src/pages/authentication/components/SignInProviders.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/authentication/components/SignInProviders.tsx b/src/pages/authentication/components/SignInProviders.tsx index e6c9f362b..4c6d0719d 100644 --- a/src/pages/authentication/components/SignInProviders.tsx +++ b/src/pages/authentication/components/SignInProviders.tsx @@ -144,7 +144,7 @@ export function SignInProviders() { Date: Tue, 3 Oct 2023 00:57:45 +1100 Subject: [PATCH 4/5] fixes for wrong redirect url --- src/pages/authentication/components/SignInProviders.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/authentication/components/SignInProviders.tsx b/src/pages/authentication/components/SignInProviders.tsx index 4c6d0719d..d99936082 100644 --- a/src/pages/authentication/components/SignInProviders.tsx +++ b/src/pages/authentication/components/SignInProviders.tsx @@ -144,7 +144,7 @@ export function SignInProviders() { Date: Tue, 3 Oct 2023 14:44:09 +1100 Subject: [PATCH 5/5] Fixes redirect URL --- src/pages/authentication/components/SignInProviders.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/authentication/components/SignInProviders.tsx b/src/pages/authentication/components/SignInProviders.tsx index d99936082..615830ee6 100644 --- a/src/pages/authentication/components/SignInProviders.tsx +++ b/src/pages/authentication/components/SignInProviders.tsx @@ -144,7 +144,7 @@ export function SignInProviders() {