Apple Sign In


Configurazione su developer.apple.com

Farà scaricare un certificato del tipo: AuthKey_[KEYID].p8

Codice php:

require 'vendor/autoload.php';


        $config = new \CurrencyFair\AppleId\Config(
            [
                \CurrencyFair\AppleId\Config::REDIRECT_URI => site_url(),
                \CurrencyFair\AppleId\Config::CLIENT_ID => get_option('fabapplelogin_client_id', ''),
                \CurrencyFair\AppleId\Config::TEAM_ID => get_option('fabapplelogin_team_id'),
                \CurrencyFair\AppleId\Config::KEY_ID => get_option('fabapplelogin_key_id'),
                \CurrencyFair\AppleId\Config::PRIVATE_KEY => FAB_PLUGIN_DIR_PATH . 'certificati/' . get_option('fabapplelogin_private_key'),
            ]
        );

        $client = \CurrencyFair\AppleId\ClientFactory::create($config);
        $jwtResponse = $client->verifyAndDecodeJwt($identityToken);

        $userArray = array(
            'id' => $jwtResponse->getSubject(),
            'email' => $jwtResponse->getEmail(),
            'firt_name' => $jwtResponse->getEmail(),
            'last_name' => '',
            'name' => $jwtResponse->getEmail(),
            //'isPrivateEmail' => $jwtResponse->getIsPrivateEmail(),
            //'getDecodedTokenObject' => $jwtResponse->getDecodedTokenObject(),
        );

        $jwt = false;
        $jwt = service::jwt_user_by_profile($userArray, 'apple');
        if (!$jwt) {
            return array(
                "code" => "error",
                "message" => "jwt_user_by_profile error",
                "data" => $jwt,
            );
        }
        return array(
            "code" => "ok",
            "message" => 'apple LoggedIn',
            "data" => $jwt,
        );

Codice Angular:

import { ResponseSignInWithApplePlugin } from '@capacitor-community/apple-sign-in';

export class UserLoginPage implements OnInit {

async appleLogin() {
    const { SignInWithApple } = Plugins

    try {
      const res: ResponseSignInWithApplePlugin = await SignInWithApple.Authorize()
      if (res.response) {
        this.spinnerDialog.show('Autenticazione in corso...');
        this.wordpress.appleLogin(res.response).subscribe(
          async (resp: any) => {
            this.spinnerDialog.hide();

            if (resp['code'] && resp['code'] == 'ok') {

              let data_resp = resp['data'];
              let user = {
                token: data_resp.token,
                username: data_resp.user_nicename,
                displayname: data_resp.user_display_name,
                email: data_resp.user_email,
                roles: data_resp.roles,
              };

              this.authentication.setUser(user);
              this.isLogged = user;
              this.fbLogs = resp['message'];

              //this.toast.show(resp['message']);

              setTimeout(() => {
                this.sharedservice.login(user);

                this.dismiss();
              }, 1000);
            } else if (resp['message']) {
              this.fbLogs = JSON.stringify(resp['data']);
              const alert = await this.alertCtrl.create({
                header: 'Signin with Apple',
                message: resp['message'],
                buttons: ['Ok']
              });
              await alert.present();
            }
          },
          async error => {
            this.spinnerDialog.hide()
            const alert = await this.alertCtrl.create({
              header: 'Signin with Apple: error',
              message: JSON.stringify(error),
              buttons: ['Ok']
            });
            await alert.present();
          }
        );
      }
    } catch (e) {
    }

  }
}

Lascia un commento

Il tuo indirizzo email non sarà pubblicato. I campi obbligatori sono contrassegnati *