forked from zammad/zammad
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature: Mobile - Login finalization: Third-party authentications.
Co-authored-by: Florian Liebe <[email protected]> Co-authored-by: Dominik Klein <[email protected]> Co-authored-by: Dusan Vuckovic <[email protected]>
- Loading branch information
1 parent
821d444
commit 657e3b4
Showing
33 changed files
with
487 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
app/frontend/apps/mobile/pages/login/components/LoginThirdParty.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<!-- Copyright (C) 2012-2023 Zammad Foundation, https://zammad-foundation.org/ --> | ||
|
||
<script setup lang="ts"> | ||
import useFingerprint from '@shared/composables/useFingerprint' | ||
import { getCSRFToken } from '@shared/server/apollo/utils/csrfToken' | ||
import type { ThirdPartyAuthProvider } from '@shared/types/authentication' | ||
|
||
export interface Props { | ||
providers: ThirdPartyAuthProvider[] | ||
} | ||
|
||
const props = defineProps<Props>() | ||
|
||
const csrfToken = getCSRFToken() | ||
|
||
const { fingerprint } = useFingerprint() | ||
</script> | ||
|
||
<template> | ||
<section class="mt-4 mb-16 w-full max-w-md"> | ||
<p class="p-3 text-center"> | ||
{{ | ||
$c.user_show_password_login | ||
? $t('Or sign in using') | ||
: $t('Sign in using') | ||
}} | ||
</p> | ||
<div class="flex flex-wrap gap-2"> | ||
<form | ||
v-for="provider of props.providers" | ||
:key="provider.name" | ||
class="min-w-1/2-2 grow" | ||
method="post" | ||
:action="`${provider.url}?fingerprint=${fingerprint}`" | ||
> | ||
<input type="hidden" name="authenticity_token" :value="csrfToken" /> | ||
<button | ||
class="flex h-14 w-full cursor-pointer select-none items-center justify-center rounded-xl bg-gray-600 py-2 px-4 text-white" | ||
> | ||
<CommonIcon | ||
:name="`mobile-${provider.icon}`" | ||
size="base" | ||
decorative | ||
class="shrink-0 ltr:mr-2.5 rtl:ml-2.5" | ||
/> | ||
<span | ||
class="overflow-hidden text-ellipsis whitespace-nowrap text-xl leading-7" | ||
> | ||
{{ $t(provider.name) }} | ||
</span> | ||
</button> | ||
</form> | ||
</div> | ||
</section> | ||
</template> |
45 changes: 45 additions & 0 deletions
45
app/frontend/apps/mobile/pages/login/components/__tests__/LoginThirdParty.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Copyright (C) 2012-2023 Zammad Foundation, https://zammad-foundation.org/ | ||
|
||
import { renderComponent } from '@tests/support/components' | ||
import LoginThirdParty from '../LoginThirdParty.vue' | ||
|
||
const renderLoginThirdParty = () => { | ||
return renderComponent(LoginThirdParty, { | ||
props: { | ||
providers: [ | ||
{ | ||
name: 'GitHub', | ||
enabled: true, | ||
icon: 'github', | ||
url: '/auth/github', | ||
}, | ||
{ | ||
name: 'GitLab', | ||
enabled: true, | ||
icon: 'gitlab', | ||
url: '/auth/gitlab', | ||
}, | ||
{ | ||
name: 'SAML', | ||
enabled: true, | ||
icon: 'saml', | ||
url: '/auth/saml', | ||
}, | ||
], | ||
}, | ||
}) | ||
} | ||
|
||
describe('LoginThirdParty.vue', () => { | ||
it('shows the third-party login buttons', () => { | ||
const view = renderLoginThirdParty() | ||
|
||
expect(view.getByText('SAML')).toBeInTheDocument() | ||
expect(view.getByText('GitHub')).toBeInTheDocument() | ||
expect(view.getByText('GitLab')).toBeInTheDocument() | ||
|
||
expect(view.getByIconName('mobile-saml')).toBeInTheDocument() | ||
expect(view.getByIconName('mobile-github')).toBeInTheDocument() | ||
expect(view.getByIconName('mobile-gitlab')).toBeInTheDocument() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
app/frontend/shared/components/CommonIcon/assets/mobile/linkedin.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
app/frontend/shared/components/CommonIcon/assets/mobile/saml.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
app/frontend/shared/components/CommonIcon/assets/mobile/sso.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
app/frontend/shared/components/CommonIcon/assets/mobile/weibo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
app/frontend/shared/composables/useThirdPartyAuthentication.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
// Copyright (C) 2012-2023 Zammad Foundation, https://zammad-foundation.org/ | ||
|
||
import { computed } from 'vue' | ||
import { storeToRefs } from 'pinia' | ||
import { i18n } from '@shared/i18n' | ||
import { useApplicationStore } from '@shared/stores/application' | ||
import type { ThirdPartyAuthProvider } from '@shared/types/authentication' | ||
|
||
export const useThirdPartyAuthentication = () => { | ||
const application = useApplicationStore() | ||
const { config } = storeToRefs(application) | ||
|
||
const providers = computed<ThirdPartyAuthProvider[]>(() => { | ||
return [ | ||
{ | ||
name: i18n.t('Facebook'), | ||
enabled: !!config.value.auth_facebook, | ||
icon: 'facebook', | ||
url: '/auth/facebook', | ||
}, | ||
{ | ||
name: i18n.t('Twitter'), | ||
enabled: !!config.value.auth_twitter, | ||
icon: 'twitter', | ||
url: '/auth/twitter', | ||
}, | ||
{ | ||
name: i18n.t('LinkedIn'), | ||
enabled: !!config.value.auth_linkedin, | ||
icon: 'linkedin', | ||
url: '/auth/linkedin', | ||
}, | ||
{ | ||
name: i18n.t('GitHub'), | ||
enabled: !!config.value.auth_github, | ||
icon: 'github', | ||
url: '/auth/github', | ||
}, | ||
{ | ||
name: i18n.t('GitLab'), | ||
enabled: !!config.value.auth_gitlab, | ||
icon: 'gitlab', | ||
url: '/auth/gitlab', | ||
}, | ||
{ | ||
name: i18n.t('Microsoft'), | ||
enabled: !!config.value.auth_microsoft_office365, | ||
icon: 'microsoft', | ||
url: '/auth/microsoft_office365', | ||
}, | ||
{ | ||
name: i18n.t('Google'), | ||
enabled: !!config.value.auth_google_oauth2, | ||
icon: 'google', | ||
url: '/auth/google_oauth2', | ||
}, | ||
{ | ||
name: i18n.t('Weibo'), | ||
enabled: !!config.value.auth_weibo, | ||
icon: 'weibo', | ||
url: '/auth/weibo', | ||
}, | ||
{ | ||
name: | ||
(config.value['auth_saml_credentials.display_name'] as string) || | ||
i18n.t('SAML'), | ||
enabled: !!config.value.auth_saml, | ||
icon: 'saml', | ||
url: '/auth/saml', | ||
}, | ||
{ | ||
name: i18n.t('SSO'), | ||
enabled: !!config.value.auth_sso, | ||
icon: 'sso', | ||
url: '/auth/sso', | ||
}, | ||
] | ||
}) | ||
|
||
const enabledProviders = computed(() => { | ||
return providers.value.filter((provider) => provider.enabled) | ||
}) | ||
|
||
return { | ||
enabledProviders: enabledProviders.value, | ||
hasEnabledProviders: enabledProviders.value.length > 0, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ export const LogoutDocument = gql` | |
mutation logout { | ||
logout { | ||
success | ||
externalLogoutUrl | ||
} | ||
} | ||
`; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
mutation logout { | ||
logout { | ||
success | ||
externalLogoutUrl | ||
} | ||
} |
Oops, something went wrong.