Base solution for your next web application
Ends in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

AbpSession don't work in mobile app #7122


User avatar
0
SASIMEXICO created

Have a trouble:

My project have a X service in [MyProject].Application.Services with override GetAll and Create methods.

  • When using swagger (web.host) or web app the Create method add in table a new record with CreationTime and CreatorUserId columns (as all services in ZERO) and also retreive the TenantId with AbpSession.TenantId
  • When launching mobile app (Android emulator) and using X service (Create method) the AbpSession is empty (UserId and TenantId null) and also the CreatorUserId is inserted in table as NULL

Other values sent from mobile to service are inserted well, just AbpSession values always null. No errors appear, only fields CreatorUserId and AbpSession.TenantId as NULL.

Why from mobile app (emulator) can't access to AbpSession? What am I doing wrong? Need help

Thanks!


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

    Does your application service method require authorization?

  • User Avatar
    0
    SASIMEXICO created

    The service require authorization, but I tested it with Authorization.Users and Anonymous decorators... Always NULL in AbpSession

  • User Avatar
    0
    maliming created
    Support Team

    It is possible that your mobile client's request did not carry a token, causing the server to fail to resolve the AbpSession.

    Try to remove AllowAnonymous and see what happens.

  • User Avatar
    0
    SASIMEXICO created

    Yes! When methods are with "AppPermissions.Pages_Administration_Users" permission, the response is "current user did not login the application".

    We are using Identity with IdentityModel (OpenId connection OAUTH), not Microsoft Identity... how the mobile app get the Token? And why using methods in web all is fine, but not in mobile?

  • User Avatar
    0
    ryancyq created
    Support Team

    Hi, you can check if the token is persisted by calling IDataStorageService.RetrieveAuthenticateResult()

    Upon login sucessfully, token will be mapped to AuthenticationResultModel and persisited.

    See https://github.com/aspnetzero/aspnet-zero-core/blob/a99934d7851ff4b55a88d3df1ab9457afd25a9be/aspnet-core/src/MyCompanyName.AbpZeroTemplate.Application.Client/ApiClient/AccessTokenManager.cs#L61-L64