Announcement Announcement Module
No announcement yet.
Getting the request IP inside ConnectionSignUp Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Getting the request IP inside ConnectionSignUp

    I'm autocreating users using ConnectionSignUp.execute(Connection<?> connection) and everything works fine, but I need to store also the ip of the request.

    How may I access the request from that method?
    Maybe it would be useful to pass it to the execute() method but that would break compatibility.

    Thanks for any help,

  • #2
    At the moment, it's not possible to do least not directly. That method is called from the repository and the repository knows nothing about the request (which is generally a good thing design-wise). It's handed a Connection object to work with and (again, generally), the connection doesn't need to know about the IP address or any other attribute of the request that led to its creation. In fact, who's to say that the connection was even created as a result of a web request? A native Android app could use the same repository to create a connection and there would be no request in play.

    One option, albeit a little indirect, is to handle this in the postSignIn() of a ProviderSignInInterceptor. You still won't be able to add th IP address to the DB when the connection is created, but you could follow up afterwards and add it. In fact, I'd be inclined not to keep the IP address in the connection table at all...instead add it to some other table that references the connection with a foreign key. But either way, I see no reason why you couldn't do this post-creation in a ProviderSignInInterceptor.


    • #3
      Hello Craig,
      to ProviderSignInInterceptor.postSignIn() is passed a WebRequest and if I'm not mistaken there is no way to get the IP address from a WebRequest.

      What am I missing?


      • #4
        Well, the WebRequest that you're given will be a NativeWebRequest and from that you can call getNativeRequest() to get an HttpServletRequest (from which you can get the IP address). You'll just need to cast the WebRequest to NativeWebRequest.