1

Is it possible to restrict an angular route by ip address or domain?

I am currently using angular 4 with asp.net web api 2. I have an admin route, but I only want the admin route to be accessed by particular ips or a domain.

xaisoft
  • 3,343
  • 8
  • 44
  • 72

1 Answers1

1

It is not possible to access IP address of a client only with JS. See this question's answer: How to get client's IP address using javascript only?

There are simple solutions in a form of API that will return you your public ip.

As for domain name you can use window object from JS to see what domain name is present:

`window.location.host' will return you domain name.

As for forbidding access to some routes you can use Angular guarding concept for that purpose:

https://angular.io/docs/ts/latest/guide/router.html#!#can-activate-guard

Community
  • 1
  • 1
Mario Petrovic
  • 7,500
  • 14
  • 42
  • 62
  • So in combination with canActivate, I can probably make a request to a server side api that will return some authorization if the request came from a certain IP? – xaisoft May 03 '17 at 14:36
  • Yes, exactly. Actually you can make a simple request to your server that can ready IP address and actually return to your guard success or fail based on read IP address of client. – Mario Petrovic May 03 '17 at 14:39