Heimdall

From Metakgp Wiki
Jump to navigation Jump to search

In Norse mythology, Heimdall (from Old Norse Heimdallr) is a god. He is the son of Odin and nine mothers. Heimdall keeps watch for invaders and the onset of Ragnarök from his dwelling Himinbjörg, where the burning rainbow bridge Bifröst meets the sky. [REF. Heimdall Wikipedia]. So basically he is the gatekeeper to Asgard.


There are times where someone needs to develop an application accessible only when connected to campus network yet they can't host it on campus network for various valid reasons. Here's where Heimdall comes to save the day! Keeping watch for invaders (request from outside campus network) invading Asgard (the application without **a backend**). So let's discuss what black magic you need to apply to achieve this.


You just need to send a GET request to https://heimdall.metakgp.org. It returns a json response with single entry (refer below). If "is_inside_kgp" is true then the request came from within campus network otherwise it originated from outside campus network, pretty straight forward, right?

{ 
 "is_inside_kgp": false
}

You must be wondering what black magic are we doing to be able to achieve this. You can refer to the code at https://github.com/metakgp/heimdall, here the need is more clearly defined in respect to frontend applications.

Need for Heimdall

Quoting the particular section for the github repository:

All this time you might be wondering why you need a different server to just check this. Can't we do this in any project where such a feature is required?

Well yes. Provided it has a backend server. This cannot be done in the front-end because the Web Browser does not provide the IP information to the Javascript engine. So for projects that do not need a backend, like [Chillzone](https://github.com/metakgp/chillzone) or [ERP Auto Login](https://github.com/metakgp/iitkgp-erp-auto-login), this simple API call can do the required work.

Other solutions

If your application has a backend then you can choose to use this or you can do it in other ways. One of them is:

  • Send ping request to any internally hosted `*.iitkgp.ac.in` site.

If the ping is successful, the request originated from within the campus network otherwise it came from outside. There is a demo implementation in iitkgp-erp-login-pypi.