capacitor-community / apple-sign-in

Sign in with Apple Support
MIT License
136 stars 59 forks source link

Add android support #12

Open no-dap opened 3 years ago

no-dap commented 3 years ago

Based on Apple's JS support, Add activity with a web view to request authorization && get the result from callback API.

Authorization request will be fired by SignInWithApple.AuthorizeAndroid().

const { SignInWithApple, Device } = Plugins;

const info = await Device.getInfo();
switch (info.platform) {
  case 'ios':
    const appleUser = await SignInWithApple.Authorize();
    // ...
    break;
  case 'android':
    const androidUser = await SignInWithApple.AuthorizeAndroid({
      // Every implementation is same as Apple's JS support
      clientId: [ClientId],
      redirectURI: [RedirectURI],
      responseType: [ResponseType],
      scope: [Scope],
      responseMode: [ResponseMode],
    });
    // ...
    break;
}

Authorization result will be sent to callback API, so I add a javascript interface to handle it inside the web view.

Callback API can simply return a value to android via window.responseHandler, something like

<script>
    window.responseHandler.setResult('{your_result}');
    window.close();
</script>
no-dap commented 3 years ago

Back button handling added

no-dap commented 3 years ago

TODO

mesqueeb commented 3 years ago

@no-dap based on the latest version, this library now has native web support.

Could you update your PR so it's based on the web support that is now already built in? Cheers!

mirko77 commented 3 years ago

@no-dap any updates? I see this PR has not been merged yet