You need to sign in to do that
Don't have an account?
Jose Cunha
how to get Guest user's IP address within @auraenabled methods?
Hi all,
I'm wondering if there's any way to obtain Guest User's IP Address within an @AuraEnabled method called by a LWC sitting on a Community.
I tried different approaches and they all failed short, let me please tell you why:
- ApexPages.currentPage().getHeaders(): It has only to do with VisualForce pages, which is not the case.
- Auth.SessionManagement.getCurrentSession(): It raises exception due to the fact that Guest users do not have sessions.
- Any sort of JS only solutions (e.g. https://api.ipify.org/): The idea behind this solution is to make a request to an external server, which is responsible to return client's ip. Then call any @AuraEnabled method to inform what IP was. Well, this seems too brittle to me. First because it introduces another point of failure (let's assume the external server is down - difficult but not impossible), second because it's to easy to dodge the second request with any arbitrary IP.
Is there any other solution I might be missing?
Thanks,
Jose
I'm wondering if there's any way to obtain Guest User's IP Address within an @AuraEnabled method called by a LWC sitting on a Community.
I tried different approaches and they all failed short, let me please tell you why:
- ApexPages.currentPage().getHeaders(): It has only to do with VisualForce pages, which is not the case.
- Auth.SessionManagement.getCurrentSession(): It raises exception due to the fact that Guest users do not have sessions.
- Any sort of JS only solutions (e.g. https://api.ipify.org/): The idea behind this solution is to make a request to an external server, which is responsible to return client's ip. Then call any @AuraEnabled method to inform what IP was. Well, this seems too brittle to me. First because it introduces another point of failure (let's assume the external server is down - difficult but not impossible), second because it's to easy to dodge the second request with any arbitrary IP.
Is there any other solution I might be missing?
Thanks,
Jose
Did you get a chance to try this alternative?
I doesn't work for obtaining the IP of the community guest user in the AuraEnabled Apex code.
It works only when the VisualPage is placed directly in the community site - in such case it produces the correct (user) IP.
Unfortunately when it's called from the Apex controller, exactly as advised - the captured IP is the IP of the Salesforce server