Part of the Social ecosystem · 70 projects
This module integrates Apple Sign-In with Drupal, allowing users to log in using their Apple accounts. It provides a dedicated login path and integrates with the Social Auth login block, requiring the Social API and Social Auth modules.
Social Auth Apple is a Apple Sign-in authentication integration for Drupal. It is
based on the Social Auth and Social API projects
It adds to the site:
- A new url: /user/login/apple.
- A settings form at /admin/config/social-api/social-auth/apple.
- A Apple logo in the Social Auth Login block.
REQUIREMENTS
This module requires the following modules:
* Social Auth (https://drupal.org/project/social_auth)
* Social API (https://drupal.org/project/social_api)
APPLE ACCOUNT / CREDENTIALS
The hardest part of the installation is to setup your credentials within the Apple Developer Account.
You can follow this guide:
https://developer.okta.com/blog/2019/06/04/what-the-heck-is-sign-in-with-apple
INSTALLATION
- Run composer to install the dependencies.
composer require "patrickbussmann/oauth2-apple:^0.2.1" - Install the dependencies: Social API and Social Auth.
- Install as you would normally install a contributed Drupal module. See:
https://drupal.org/documentation/install/modules-themes/modules-8
for further information.
MAP FIRSTNAME / LASTNAME TO USERPROFILE
The name is only fetched the absolute first time the user logs in with the Apple ID. If you want to reset the Apple Sign-In, you have to login with your Apple ID on https://appleid.apple.com/ and remove your app from the allowed list. Also delete any related existing users in your Drupal database.
You can map the name implementing an EventSubscriber in a custom module.
Code example
<?php
namespace Drupal\my_module\EventSubscriber;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\social_auth\Event\SocialAuthEvents;
use Drupal\social_auth\Event\UserFieldsEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
/**
* Sets the domain context for an http request.
*/
class MyModuleSubscriber implements EventSubscriberInterface {
use StringTranslationTrait;
public function onSocialUserFields(UserFieldsEvent $event) {
$social_user = $event->getSocialAuthUser();
$fields = $event->getUserFields();
if ($event->getPluginId() == 'social_auth_apple') {
$parts = explode('@', $social_user->getEmail());
$additional_data = $social_user->getAdditionalData();
$fields['field_firstname'] = 'Apple ' . $this->t('Given name') . ' ' . $parts[0];
if (!empty($additional_data['name']['firstName'])) {
$fields['field_firstname'] = $additional_data['name']['firstName'];
}
$fields['field_name'] = 'Apple ' . $this->t('Last name') . ' ' . $parts[0];
if (!empty($additional_data['name']['lastName'])) {
$fields['field_name'] = $additional_data['name']['lastName'];
}
$event->setUserFields($fields);
}
}
public static function getSubscribedEvents() {
// This needs to fire very early in the stack, before accounts are cached.
$events[SocialAuthEvents::USER_FIELDS][] = ['onSocialUserFields', 0];
return $events;
}
}
Ask your assistant about Social Auth Apple Sign-In
Check compatibility with your Drupal and PHP version, maintenance and security coverage, from current release data. How it works
Depends on
Dependencies of the latest stable release
Required by
Tracked projects that depend on this one
No tracked projects depend on this one yet.
More in the Social ecosystem
Most installed first