Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apple login #1146

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
37 changes: 37 additions & 0 deletions src/pages/authentication/components/SignInProviders.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ 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';
import { v4 } from 'uuid';

export const msal = new PublicClientApplication({
auth: {
Expand Down Expand Up @@ -91,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,
Expand Down Expand Up @@ -134,6 +142,35 @@ export function SignInProviders() {
<p>Log in with Microsoft</p>
</SignInProviderButton>

<AppleLogin
clientId="com.invoiceninja.client"
redirectURI="https://invoicing.co/auth/apple"
scope='name email'
responseType='code id_token'
responseMode='form_post' //may not be accurate
usePopup={true}
nonce={v4()}
callback={(response) => {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
@typescript-eslint/ban-ts-comment
Expand Down