API Security: how to restrict access by domain?

2020-03-04 02:30发布

I'm exposing a simple API and need to make sure only authorized users access it. I will be providing an API key to authenticate. However, I also want to associate the API key to a certain domain (meaning, it should only work if it's being used from the authorized domain(s)).

How do I check on the API side if it is being accessed from an authorized domain? HTTP_REFERER apparently is not reliable. Suggestions?

标签: php security api
3条回答
放我归山
2楼-- · 2020-03-04 02:55

HTTP+SSL is a complex protocol set that supports certificates for both server and the client, and probably could be used in this case, but somehow I feel this would be an overkill.

查看更多
等我变得足够好
3楼-- · 2020-03-04 02:58

What kind of API are you exposing? There are many different kinds of APIs - I assume you do not expose your operating system's API...

Assuming you want to expose some web application's API, you may take a look at OAuth, which is based on callback URLs - you can just block certain domains from being called through callback URL.

Read more about OAuth.

查看更多
beautiful°
4楼-- · 2020-03-04 03:09

you want the source IP address

REMOTE_ADDR -or- HTTP_X_FORWARDED_FOR

查看更多
登录 后发表回答