Base solution for your next web application
Open Closed

Apple Sign-In #10530


User avatar
0
ernestoBS created
  • What is your product version? 10.3
  • What is your product type (Angular or MVC)? Angular 9
  • What is product framework type (.net framework or .net core)? .net core 5

We need to implement Apple Sign-in, we already used Facebook and Google that came out-off the box. Which classes of the Aspnetzero solution do we need to extend to implement the apple sign-in the proper way? I do know how to do it in a generic Asp .net core solution. This question is regarding Aspnetzero. In the Backend after I get the proper data from Apple, how do I get the LogInManager.LoginAsync() that is called in the ExternalAuthentication logic to validate the tokens and return success and then get the rest of the method to work just like with the Facebook and Google providers? I just interested in Backend code changes.

Really looking forward to hear back from you guys! Thanks, L.


1 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @ernestoBS

    We haven't implemented Apple Sign-In before but I can explain how the external login works in the Angular version.

    Here are the steps;

    1. Angular client redirects (or opens a popup for some providers) user to the target platform for login.
    2. Target platform redirects user back to AspNet Zero's Angular app with auth information like id_token, access_token etc...
    3. Then, AspNet Zero's Angular app sends these information to TokenAuthController's ExternalAuthenticate method, here.
    4. In GetExternalUserInfo metrhod, you can add an if statement and request user's information from Apple as shown below;
    private async Task<ExternalAuthUserInfo> GetExternalUserInfo(ExternalAuthenticateModel model)
    {
        var userInfo = new ExternalAuthUserInfo();
        if(model.AuthProvider == "Apple"){
            var userInfo = GetAppleUserInfo(model.ProviderAccessCode); // you need to create GetAppleUserInfo method
        }else{
            userInfo = await _externalAuthManager.GetUserInfo(model.AuthProvider, model.ProviderAccessCode);
        }
        
        if (!ProviderKeysAreEqual(model, userInfo))
        {
            throw new UserFriendlyException(L("CouldNotValidateExternalUser"));
        }
    
        return userInfo;
    }
    

    Rest should work as expected.