We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 14883 ☆ A M B ☆
    • 450 Posts
    I have a secure domain with a separate context where I am logging a user in as 'userx'. I then want them to be able to access some resources on my 'web' context that require membership in a user group that 'userx' is a member of.

    However, the problem seems to be that even though the user is logged in as 'userx' in my 'secure' context, they are still 'anonymous' in my web context.

    How would I (through snippet API code) get the 'web' context to recognize that the user has logged in & is no longer anonymous?
      • 4172
      • 5,888 Posts
      I think you can a user programmatically log in to a context by
      $user->addSessionContext('web');
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 14883 ☆ A M B ☆
        • 450 Posts
        I've tried using addSessionContext, and it seems like it works, but... the unauthorized pages are still unauthorized.

        One thing I'm seeing is that there are session vars for both user 0 and user 35 (the user I'm logging them in as).

        modx.user.0.attributes:Array
        
        modx.user.0.resourceGroups:Array
        
        modx.user.contextTokens:Array
        
        modx.secure.user.token:modx4f2c0964aac3b1.13091856_354fd606c5e50737.21839180
        
        modx.secure.session.cookie.lifetime:0
        
        modx.user.35.attributes:Array
        
        modx.user.35.resourceGroups:Array
        
        modx.web.user.token:modx4f2c0964aac3b1.13091856_354fd606d44af500.11083884
        
        modx.user.35.userGroups:Array
        
        modx.user.35.userGroupNames:Array
          • 22303 MODX Staff
          • 10,725 Posts
          This will ONLY work if web and secure are the same domain (or subdomains of the same domain and you have session cookies configured to support that). Is this the case here?
            • 14883 ☆ A M B ☆
            • 450 Posts
            They ARE subdomains of the same domain.

            I almost surely do not "have session cookies configured to support that". What steps do I need to follow to do so?
              • 14883 ☆ A M B ☆
              • 450 Posts
              I found what I needed here:
              http://rtfm.modx.com/display/revolution20/session_cookie_domain

              and I think I solved my problem!
                • 22303 MODX Staff
                • 10,725 Posts
                Great! Let us know if you have any other issues...