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

authorize(options) doesn't work with iOS 14 and 15 #60

Open
TheNemus opened this issue Oct 11, 2021 · 30 comments
Open

authorize(options) doesn't work with iOS 14 and 15 #60

TheNemus opened this issue Oct 11, 2021 · 30 comments

Comments

@TheNemus
Copy link

TheNemus commented Oct 11, 2021

Describe the bug
If I try to star the authorization in iOS14-15, nothing happens.
The 'authorize' method promise never resolves.

To Reproduce
Steps to reproduce the behavior:

  1. Implement the authorize()
  2. Click on the "sign in with apple" button
  3. Fill with your credential
  4. See nothing happening

Expected behavior
Get a response with the user informations

Screenshots
Simulator Screen Shot - iPhone 11 - 2021-10-11 at 16 15 05

Smartphone (please complete the following information):

  • Device: iPhone-iPad(simulator and real devices)
  • OS: iOS14-15
  • plugin vers: 0.1.x-1.0.x
@ciccilleju
Copy link

having the same issue: did you find any workaround?

@timeisgolden
Copy link

having the same issue. Anyone solved this issue?

@ciccilleju
Copy link

ciccilleju commented Oct 20, 2021 via email

@timeisgolden
Copy link

wow, that's great, @ciccilleju thanks for your reply.
so did you use v1.0.1?

@ciccilleju
Copy link

ciccilleju commented Oct 20, 2021 via email

@timeisgolden
Copy link

timeisgolden commented Oct 20, 2021

let options: SignInWithAppleOptions = {
        clientId: 'jeffrey.app',
        redirectURI: 'https://www.yourfrontend.com/login',
        scopes: 'email',
        state: '12345',
        nonce: 'nonce',
      };
      SignInWithApple.authorize(options).then((result: SignInWithAppleResponse) => {
        console.log("Debug apple login:", JSON.stringify(result.response));
});

I am trying to apple login with v1.0.1.
but I failed.
I don't know clientId, redirectURI well.
Do you know that well?

@ciccilleju
Copy link

ciccilleju commented Oct 20, 2021 via email

@ciccilleju
Copy link

here a sample of my code:

the ts file:

import {
SignInWithApple,
SignInWithAppleOptions,
SignInWithAppleResponse
} from '@capacitor-community/apple-sign-in';

@Injectable({
providedIn: 'root'
})

export class AppleSigninService {
userData: any;
token: any;
serviziRest: any = serviziRest;

constructor(
) {

}

openAppleSignIn() {

let options: SignInWithAppleOptions = {
  clientId: 'myapp.mybundle.com',
  redirectURI: '',
  scopes: 'email, name',
  state: '12345',
  nonce: 'nonce'
};



SignInWithApple.authorize(options)
  .then(async (res: SignInWithAppleResponse) => {
    console.log(res);
    if (res.response && res.response.identityToken) {
     alert(JSON.stringify(res));
    } else {
      this.alertService.alertError('Error Apple Signin');
    }
  })
  .catch((error) => {
    console.error(error);
    this.alertService.alertError(error);
  });

}

}

the html file has just the function call to openAppleSignIn()

@ciccilleju
Copy link

did you add the sign in capability in your xcode? you need to enable it from your developer account and then add to xcode from here:
image

@timeisgolden
Copy link

yeah, of course, I added the capability in Xcode.

@timeisgolden
Copy link

ERROR {"code":"auth/missing-or-invalid-nonce","message":"Nonce is missing in the request."}

this is the error message when apple logged in

@timeisgolden
Copy link

in SignIn Options,
clientId is same as app bundle Id?

@timeisgolden
Copy link

timeisgolden commented Oct 20, 2021

Yes exactly, I have installed the library with npm, imported it in the typescript file, and then ran the authorize function. I got the response back with all my data(token, email, name, surname). Beware that you will get those info only at the first login attempt, all the other times you will get "null" for those fields but idToken. For getting them back you need to remove the authorization from your device from options->apple id-> your app Il Mer 20 Ott 2021, 20:03 devmanagalaxy @.***> ha scritto:

wow, that's great, @ciccilleju https://github.com/ciccilleju thanks for your reply. so did you use v1.0.1? — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub <#60 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AKFB5GSWF4YAYCRYNAK3MJDUH3773ANCNFSM5FYLGNFQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

For getting them back you need to remove the authorization from your device from options->apple id-> your app

I didn't find the path.
can you share that as screenshot how I can remove the authorization from my iphone?

@timeisgolden
Copy link

{"authorizationCode":"cb5b9e6f054484070bbae53d461aa8d3b.0.sxzs.OJCuk02wLs7BKvJiHz-c5Q","identityToken":"eyJraWQiOiI4NkQ4OEtmIiwiYWxnIjoiUlMyNTYifQ.eyJpc3MiOiJodHRwczovL2FwcGxlaWQuYXBwbGUuY29tIiwiYXVkIjoiamVmZnJleS5hcHAiLCJleHAiOjE2MzQ4NDE0MTMsImlhdCI6MTYzNDc1NTAxMywic3ViIjoiMDAwNzkyLjQyNDI0NTAwYTIyMzRkNTBhNDg5ZWQwOTA0NzM5MDEyLjAyMjIiLCJub25jZSI6Im5vbmNlIiwiY19oYXNoIjoib1JSZlhTaXJHS2N6SmczV0FhcXhOQSIsImF1dGhfdGltZSI6MTYzNDc1NTAxMywibm9uY2Vfc3VwcG9ydGVkIjp0cnVlfQ.PBdIn45BMyx9PGjJm5VTpg9YGWvJ9WkcOpG-dGHF40z1j8NsRCj_3S_mCJsju8ak5rGqR5RZV-gHhm6NJT6xP1hvAOPG9eanNr9aH0H5XY4rZfZKGs67jQ-JllWMloPSda4Yu-6FjPuCdFSJa1w1YQdUGDO-x2h3yC1lkA6COGymYDPMZIdU4Qjq0c6wrAu4o2lFE8fqUk88apZlQVqPhLZLh549g_6wxweuTunBF0OsK7acreOQkwBIPyGrrDOmq96fVv8b0kDwcdOY4A_y6apEqcC1p0j2TL2aXqrHW8LVV97ZvN3JTe_q6wYqf2Ka44C5yhLO0PYIqEDdII6oMQ","givenName":null,"familyName":null,"user":"000792.42424500a2234d50a489ed0904739012.0222","email":null}

you are right, I am getting null of email, familyName and givenName.
plz help me.

@ciccilleju
Copy link

ciccilleju commented Oct 20, 2021 via email

@ciccilleju
Copy link

Inside your iOS device, open the settings app and navigate to Apple ID -> Password & Security -> Apple ID logins. In this screen, you can see all the apps where you used Apple Sign In, and you can simply delete the entry for your own app.

image
Now you can test the process again inside your app, and the initial dialog to sign in will show up again like in the image you see below.

@timeisgolden
Copy link

Thanks, I can get the correct email, givenName after removing my app from apple id logins.

last question, should I remove my app from apple id logins whenever apple login?

@ciccilleju
Copy link

ciccilleju commented Oct 20, 2021 via email

@timeisgolden
Copy link

Thanks,
There is any method to unauthorize apple(mean logout)?
or is this a stupid question?

@ciccilleju
Copy link

ciccilleju commented Oct 20, 2021 via email

@sbellver
Copy link

I'm in the same point.

Captura de pantalla 2021-10-22 a las 14 18 12

When I set the password, I don't have any alert or console log to see the response

Using Vue (not typescript)

async loginApple() {
      const options = {
        clientId: 'es.yakk',
        redirectURI: '',
        scopes: 'email, name',
        state: '12345',
        nonce: 'nonce',
      };

      SignInWithApple.authorize(options)
        .then((res) => {
          alert(JSON.stringify(res));
          if (res.response && res.response.identityToken) {
            alert(JSON.stringify(res));
          } else {
            this.alertService.alertError('Error Apple Signin');
            alert('ERROR');
          }
        })
        .catch((error) => {
          console.error(error);
          this.alertService.alertError(error);
          alert('ERROR FINAL');
        });
    },

If I set an incorrect password, it fails.

If I set the correct password, it don't show anything

If I cancel, I got the debug message

2021-10-22 14:31:06.314334+0200 App[69005:2760796] [core] Authorization failed: Error Domain=AKAuthenticationError Code=-7003 "(null)" UserInfo={AKClientBundleID=es.yakk}
ERROR MESSAGE:  {"errorMessage":"The operation couldn’t be completed. (com.apple.AuthenticationServices.AuthorizationError error 1001.)","message":"The operation couldn’t be completed. (com.apple.AuthenticationServices.AuthorizationError error 1001.)"}
⚡️  [error] - {"errorMessage":"The operation couldn’t be completed. 

@sbellver
Copy link

It actually works on real devices. I've made it working Il Mer 20 Ott 2021, 19:59 devmanagalaxy @.***> ha scritto:

Then, only works on real device???

@timeisgolden
Copy link

It actually works on real devices. I've made it working Il Mer 20 Ott 2021, 19:59 devmanagalaxy @.***> ha scritto:

Then, only works on real device???

yeah, that only worked on real devices.

@katche70
Copy link

here a sample of my code:

the ts file:

import { SignInWithApple, SignInWithAppleOptions, SignInWithAppleResponse } from '@capacitor-community/apple-sign-in';

@Injectable({ providedIn: 'root' })

export class AppleSigninService { userData: any; token: any; serviziRest: any = serviziRest;

constructor( ) {

}

openAppleSignIn() {

let options: SignInWithAppleOptions = {
  clientId: 'myapp.mybundle.com',
  redirectURI: '',
  scopes: 'email, name',
  state: '12345',
  nonce: 'nonce'
};



SignInWithApple.authorize(options)
  .then(async (res: SignInWithAppleResponse) => {
    console.log(res);
    if (res.response && res.response.identityToken) {
     alert(JSON.stringify(res));
    } else {
      this.alertService.alertError('Error Apple Signin');
    }
  })
  .catch((error) => {
    console.error(error);
    this.alertService.alertError(error);
  });

}

}

the html file has just the function call to openAppleSignIn()

i tried your code on real device and ist not working.
It's logging:
[error] - {"code":"UNIMPLEMENTED"}

Any suggestions?

@sbellver
Copy link

Here is my code, it's vue:

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

async loginApple() {
      const options = {
        clientId: 'my.bundle.app',
        redirectURI: '',
        scopes: 'email, name',
        state: '12345',
        nonce: 'nonce',
      };

      await SignInWithApple.authorize(options)
        .then(async (res) => {
          if (res.response && res.response.identityToken) {
            this.$api.post('apple_login', res.response).then(({ data }) => {
              this.$apidefaults.headers = { common: { Authorization: `Bearer ${data.token}` } };
              this.$q.localStorage.set('token', data.token);
              this.$q.localStorage.set('user', data.user);
              this.$store.commit('user', data.user);
              this.$router.push({ name: 'home' });
            }).catch((error) => {
              this.$router.push({ name: 'signup', params: res.response });
              console.log(error);
            });
          } else {
            this.alertService.alertError('Error Apple Signin');
          }
        })
        .catch((error) => {
          console.error(error);
          alert('Cancelado por el usuario');
        });
    },

Only works on real device, in emulator I can see anything

@katche70
Copy link

katche70 commented Oct 29, 2021

@sbellver
not working for me on real device.
`
async loginApple() {

const options = {
  clientId: 'my.bundle.app',
  redirectURI: '',
  scopes: 'email, name',
  state: '12345',
  nonce: 'nonce',
};

await SignInWithApple.authorize(options)
  .then(async (res) => {
    console.log('SignInWithApple', res);
  })
  .catch((error) => {
    console.error('Error SignInWithApple', error);
  });

}`
Just get
[error] - Error SignInWithApple {"code":"UNIMPLEMENTED"}

To clarify - clientId must be "Bundle ID" from Identifiers certificate and capabilites "Sign In with Apple" must be checked
image

After adding it apple writes:
Modify App Capabilities
Adding or removing any capabilities will invalidate any provisioning profiles that include this App ID and they must be regenerated for future use.

Maybe this is where the problem comes from

@katche70
Copy link

katche70 commented Nov 3, 2021

Using unofficial, 2years old version https://github.com/rlfrahm/capacitor-apple-login of apple-sign-in solved my problem.

@arielhasidim
Copy link

ERROR {"code":"auth/missing-or-invalid-nonce","message":"Nonce is missing in the request."}

this is the error message when apple logged in

Check my answer here: #65

@janehernandez
Copy link

Do you have any idea how to setup clientId and redirectUrl for capacitor v.0.2.0??

#73

@sebaparedero14
Copy link

any workaround?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants