Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What to set the redirectUri for Apple SignIn with Flutter for android

In my flutter app I'm attempting to setup apple sign in on android using the sign_in_with_apple_package I'm having trouble figuring out what to set the redirectUri to.

This is what I have:

appleCredential = await SignInWithApple.getAppleIDCredential(
   scopes: [
     AppleIDAuthorizationScopes.email,
     AppleIDAuthorizationScopes.fullName,
   ],
   webAuthenticationOptions: WebAuthenticationOptions(
     clientId: "SERVICE_IDENTIFIER",
     redirectUri: NEED_THIS,
   ),
 );

The package docs say to use: intent://callback?${PARAMETERS FROM CALLBACK BODY}#Intent;package=YOUR.PACKAGE.IDENTIFIER;scheme=signinwithapple;end with a pretty confusing description.

I'm using a django backend so the apple sign in going through that, everything is working on iOS, if I provide a redirectUrl like https://MY_DOMAIN/accounts/apple/login/callback the apple sign in flow works, but at the end goes to a page not found.

So maybe the real question is, what do I need that redirect url to do on the server? The sing_in_with_apple example has a comment for Android you will be using the API server that redirects back into your app via a deep link

So does this mean I need to deep link my redirect url back to my android app? Has anyone done this?

like image 314
projectmind Avatar asked Nov 28 '25 19:11

projectmind


1 Answers

In WebAuthenticationOptions, redirectUri will change depending on your platform. On ios and web, you can just put your domain name. On android, you need to pass in a uri from your own server which will return a redirect to an android deep link.

Here's an example of the flutter code:

final credential = await SignInWithApple.getAppleIDCredential(
          scopes: [AppleIDAuthorizationScopes.email],
          webAuthenticationOptions: WebAuthenticationOptions(
              clientId: userService.platform != "apple"
                  ? 'com.example-service.example'
                  : 'com.example.example',
              redirectUri: userService.platform == "android" ?
            Uri.parse('https://example.com/apple/login/callback')
            : Uri.parse('https://example.com')));

Here's an example of the callback endpoint that should be added to your own server in python with fastapi:

@router.post("/apple/login/callback", response_class=RedirectResponse)
async def android_siwa(request: Request):
    args = ""
    form = await request.form()
    data = {k: v for k, v in form.items() if k != "upload-file"}
    for k, v in data.items():
        args += f"{k}={v}&"
    args = args[:-1]
    return f"intent://callback?{args}#Intent;package={settings.ANDROID_PACKAGE_NAME};scheme=signinwithapple;end"

And last thing, make sure to include both redirect URIs in your service id configuration: https://developer.apple.com/account/resources/identifiers/list/serviceId

Sign In with Apple Configuration

like image 173
Brian Y. Avatar answered Nov 30 '25 12:11

Brian Y.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!