I have a web service S that provides certain services. There are two web apps, A1 and A2, both on different servers within the same VPN, which I trust and want to grant access to my web service.
+------+ HTTPS +-----+ HTTPS +------+
| A1 | <---------> | S | <---------> | A2 |
+------+ +-----+ +------+
^ ^ VPN
. .|. . . . . . . . . . . . . . . . . . . . .|. . . . . . . .
| | Internet
| +----------+ |
| +----------+ |-------------------+
+--------| Browsers |-+
+----------+
However, I want to be able to distinguish in S between clients A1 and A2. A1 might not have the same privileges in S as A2. Moreover, I can't be sure there might not be some other web app A3 around that some evil guy installed in the same VPN. So, the basic problem is that S needs to know who it's talking to.
Some more clarification: A1 is JavaScript-based. A JavaScript in a browser is talking to the web server A1. The JavaScript is never directly talking to S, however. The web server A1 has some means to forward messages to S, e.g. a simple PHP script. There is probably no way to block evil users from contacting S through A1 in the same way as the JavaScript does. To prevent abuse of this, S is a session-based service that requires a username and a password to generate a session key. Browsers pass the session key to A1 or A2, which then pass it on to S.
The question is: How can S safely identify A1 and A2 and block any other calls?