Base solution for your next web application
Open Closed

Is there an API to Signup/Login user on .Net Core side after registering user on mobile app using social logins? #11800


User avatar
0
huntethan89 created

Hi,

I am using ASP.Net Core MVC project 12.4.0. I am using the project to create APIs for the native IOS mobile application built using swift etc. I want to register the user on backend for API once the user logged into mobile app using one of the social logins such as Google, Microsoft and Apple etc. Is there any API to register/login the same user on backend as all the claims and social signup is being done at mobile app end? Also, please suggest the best way to implement this in ASP.Net Core.


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

    Hi,

    Yes, you can login a new user using https://github.com/aspnetzero/aspnet-zero-core/blob/dev/aspnet-core/src/MyCompanyName.AbpZeroTemplate.Application/Authorization/Accounts/AccountAppService.cs#L98 (Register endpoint in AccountAppService) but this doesn't login the user immediately. Then you need to call authenticate endpoint on TokenAuthController.

  • User Avatar
    0
    huntethan89 created

    Hi,

    The link is not working and giving error and I think this API is applicable to register user via email and password. However, I want an API for external authentication of a user on net zero side after authenticating the same user though any of social login on native iOS app. Please suggest, how can we do that OR can you give us some direction on this?

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    To see that link, please add your GitHub user on https://aspnetzero.com/LicenseManagement page.

    For token based authentication, see https://docs.aspnetzero.com/en/aspnet-core-angular/latest/Features-Angular-Token-Based-Authentication

  • User Avatar
    0
    huntethan89 created

    Hi Team,

    Let me explain the real scenario. We are building iOS native app (using Swift) and enabling social authentications for Google, Microsoft, and Facebook from the app only. On the other side, we are building a web application (using asp.net zero) to perform some operations via API only. My question is as follows

    1. How can we generate the access token in server side (aspnet zero) for the user which already been authenticated via native app?
    2. Will TokenAuth >> ExternalAuthenticator work on the above scenarios?
    3. We are getting Error Unknown external auth provider: Google
    4. From where we should get the providerAccessCode (Google, Microsoft and Facebbok) for ExternalAuthenticator API

    { "authProvider": "string", "providerKey": "string", "providerAccessCode": "string", "returnUrl": "string", "singleSignIn": true }

    Please suggest to us how can we do that OR can you give us some direction on this?

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @huntethan89

    Instead of answering each question, let me explain the correct login flow. I think it will be more helpful. First of all, you can use TokenAuth/ExternalAuthenticate which will create access token for you.

    Your scenario is similar to what we implement in our Angular client. When a user clicks the external login (Google, Microsoft and Facebook etc...) button on login page;

    1. User is redirected to external website for login
    2. User is redirected back to app (Angular or mobile app) with some info (authorization code, token for external system etc... depending on the configured flow)
    3. Then, we send these info to TokenAuth/ExternalAuthenticate endpoint.
    4. ExternalAuthenticate endpoint creates a database record in AbpUsers and AbpUserLogins tables (if it doesn't exist) and then creates an access token for the record in AbpUsers table.
    5. Client app (Angular or mobile app) gets the access token created by AspNet Zero's API app and stores it.
    6. Client app (Angular or mobile app) sends the stored access token with each request header named Authorization with a value like Bearer <accessToken>

    In order to use an external provider, you must enable it in appsettings.json file and provide necessary configuration. For example, for Google, you need to fill config below;