4

I am creating a Login Flow that invokes Apex to do some processing, and need to determine whether the running (logging-in) user is connecting from an IP address whitelisted in our org's Trusted IP Ranges (as defined in Setup > Network Access > Trusted IP Ranges).

7

You can accomplish this with Auth.SessionManagement class methods. The code below sets the isTrustedIp variable based on whether or not the running user's IP address is in the trusted ranges (as defined in Setup > Network Access > Trusted IP Ranges):

        Boolean isTrustedIp = false;

        Map<String, String> sessionAttributes;
        try {
            sessionAttributes = Auth.SessionManagement.getCurrentSession();
        } catch(Exception e) {
            isTrustedIp = false;
            // TODO handle unexpected error...
        }

        String sourceIp = sessionAttributes.get('SourceIp');
        if(sourceIp != null) {
            isTrustedIp = Auth.SessionManagement.inOrgNetworkRange(sourceIp);
        }

        // TODO do something with isTrustedIp...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.