Physical Address
304 North Cardinal St.
Dorchester Center, MA 02124
Physical Address
304 North Cardinal St.
Dorchester Center, MA 02124
I created an api for my all my customers to have the ability to retrieve with corresponding information. I might restriced the api endpoints with apiKey, and origin from the headers.
Solely permit to devour my api information by checking these particular origin and api_key from the headers.
I don’t know the way to I get to restric for the cell app. A few of my customers are utilizing my api with by constructing their very own api. I do wish to rectrict them to devour my api’s information by limiting origin similar to I’m doing for the web site.
The primary query is “How do I get the precise app of their orign tackle similar to we’re coping with for the online frontend browser?”
These are the pattern to guard my very own api endpoint which I might written in NextJS.
// Examine headers username and api_key
const username = req.headers.username
const api_key = req.headers['api_key']
// Solely permit web site with orign title can retrieve information
const origin = req.headers.origin
// if the consumer is utilizing Cellular Machine then prohibit the entry
// I might solely examine who're retrieve my api from their finish by utilizing user-agent
if (req.headers['user-agent'].consists of('Cellular')) {
res.standing(403).json({
standing: 'error',
message: 'Entry denied',
})
}
const customers = subscribeAPIUsers.discover(
(person) =>
person.username === username &&
person.api_key === api_key &&
origin === person.host
)
// If person will not be discovered
if (!customers) {
res.standing(401).json({
standing: 'error',
message: 'Unauthorized',
})
}
Any ideas could be admire it. 🙂