Base solution for your next web application
Open Closed

Getting tenantID when using Token Authorisation #1662


User avatar
0
kirkjones created

Hi Guys,

I'm evaluating the template and so far it has been awesome the amount of work put in by you guys.

I have one query and it resolves around Tokens. I was able to login and receive a token and I've also been able to successfully call some of my Get services without issue. I get the objects returned (though it seems to ignore the DTO i have defined and returns all the fields).

When I try to create a new object using the dynamic api however I run into an issue of getting the tenantID which is required for multi tenant apps. The call in my service uses AbpSession.GetTenantId() which seems to get this information from the cookie based system. The basic question is how would I go about getting the current tenant information when using the WebAPI and token based authorization so it can be passed into my service so the object can be saved.

I hope my question was clear. If you need any further clarification please let me know.

Kirk


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

    Hi,

    though it seems to ignore the DTO i have defined and returns all the fields

    This is impossible :) You probably returned the Entity accidently. ABP can not do this, it returns to the client what you return from the method.

    For the TenantId question; You can get TenantId from a token based authenticated client too if you sent TenancyName to this method (<a class="postlink" href="https://github.com/aspnetboilerplate/module-zero-template/blob/master/src/AbpCompanyName.AbpProjectName.WebApi/Api/Controllers/AccountController.cs#L35">https://github.com/aspnetboilerplate/mo ... ler.cs#L35</a>) while authenticating. If you have created your template fro aspnetboilerplate.com and it's not working like that, please write again and we try to repeat the problem.

    Have a nice day.

  • User Avatar
    0
    kirkjones created

    This is impossible You probably returned the Entity accidently. ABP can not do this, it returns to the client what you return from the method.

    :D You were quite correct. I was using the FullAuditedDto which as the name suggests shows all the audit fields. I changed it and it works as expected.

    For the TenantId question; You can get TenantId from a token based authenticated client too if you sent TenancyName to this method (<a class="postlink" href="https://github.com/aspnetboilerplate/mo">https://github.com/aspnetboilerplate/mo</a> ... ler.cs#L35) while authenticating. If you have created your template fro aspnetboilerplate.com and it's not working like that, please write again and we try to repeat the problem.

    Yes, that's the method that I am calling via Postman, I get the token as expected when I then go to create an object via a create service that I created (using the same token) it returns with error code: 0 and message: "An internal error occurred during your request" When I set a breakpoint on the AbpSession.GetTenantId() it's trying to get the information from the claimsABPSession as it should but it returns UserID = 1 and TenantId = null MultitenacySide = HOST. I am logging in using default, admin and 123qwe. This is from an aspnetboilerplate template that I created on your website almost 2 weeks ago.

    Let me know if there is anything else you want me to try, I'll keep digging around to see if I can find the issue.

    Thanks a lot.

  • User Avatar
    0
    hikalkan created
    Support Team

    Thank you. Then let us to check this. Follow the issue: <a class="postlink" href="https://github.com/aspnetboilerplate/module-zero-template/issues/64">https://github.com/aspnetboilerplate/mo ... /issues/64</a>

  • User Avatar
    0
    kirkjones created

    Quick update.

    The issue was that I was misspelling tenancyName while using Postman to test and as a result it wasn't actually passing in the tenant into the login function and I was actually logged in as host. So you can close this issue, it was my mistake.

    Thanks again for your assistance and congrats on reaching version 1.0.0.

    Kirk

  • User Avatar
    0
    hikalkan created
    Support Team

    Closed the issue. Thank you for informing.